forked from Jiangtang/Programming-SAS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLatin2Eng.sas
110 lines (85 loc) · 3.74 KB
/
Latin2Eng.sas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
*******************************************************************************************************************;
*Program Name : Latin2Eng.sas *;
*Programmer Name : Jiangtang Hu *;
* [email protected] *;
* Jiangtanghu.com/blog *;
* *;
*Purpose : Translate Latin sentence to English *;
* *;
*Input : Input_Latin - the Latin sentence *;
*Output : A Cartesian combination of all seperated Latin words (word to word translation) *;
*Usage : %Latin2Eng(draco dormiens nunquam titillandus) *;
* *;
*References : WORDS - Version 1.97FC, by William Whitaker *;
* a LATIN-ENGLISH DICTIONARY PROGRAM, http://users.erols.com/whitaker/words.htm *;
* *;
*License : public domain, ABSOLUTELY NO WARRANTY *;
*Platform : tested in WinXP SAS/Base 9.2 *;
*Version : V1.1 *;
*Date : 08Oct2011 *;
*******************************************************************************************************************;
/*macro to recursively creat string list like
ff1,ff2,ff3,ff4...
test:
%put %_list(4);
*/
%macro _list(n,pre=ff);
%if &n=1 %then &pre.1;
%else %_list(%eval(&n-1)),&pre.&n;
%mend _list;
/*core macro: from Latin to English*/
%macro Latin2Eng(Input_Latin,engine=http://lysy2.archives.nd.edu/cgi-bin/words.exe?);
data URL;
Input_Latin="&Input_Latin";
engine="&engine";
i=1;
do while (scan(Input_Latin,i) ne "");
input=scan(Input_Latin,i);
URL=compress(input);
output;
i=i+1;
end;
run;
data _null_;
set URL end=eof;
II=left(put(i,2.));
call symputx('URL'||II,URL);
if eof then call symputx('total',II);
run;
%do i=1 %to &total;
filename f&i URL "&engine.&&URL&i";
data f&i;
length text $1024;
infile f&i lrecl=1024;
input text $;
text= _infile_;
if index(text,"<") then delete; *need to improve;
if index(text,"*") then delete; *need to improve;
run;
data ff&i;
set f&i end=eof;
if eof;
j=1;
do while (scan(text,j,";") ne "");
&&URL&i=scan(text,j,";");
output;
j=j+1;
end;
drop text j;
run;
%end;
data all;
merge %do i=1 %to &total; ff&i %end;;
run;
proc print data=all;
run;
proc sql;
create table Cartesian as
select *
from %_list(&total)
;
quit;
proc print data=Cartesian;
run;
%mend Latin2Eng;
%*Latin2Eng(draco dormiens nunquam titillandus)