程序是用SAS寫的,本來也打算用python寫的,碰到困難,就用SAS了(SAS也困難重重,寫了一天,才搞定,╮(╯_╰)╭)
首先獲取數據,本程序利用了宏變量,宏程序;宏變量寫在程序開頭,方便修改
libname aa "d:\english_word";
/*是否合格的定義:大于候選個數限制且長度大于已輸入單詞,的為不合格*/
%let wait_max=5;/*候選個數限制*/
%let infile="d:\word.txt";
%let outfile="d:\output.txt";
/*讀取txt*/
data aa.allword_temp;
infile &infile.;
attrib word length=$20.;
input word $;
/*input word $20.;*/
/*是錯誤寫法,$20.指連續的20位,效果是每隔一行讀一次,語法錯誤會導致各種奇怪的錯誤*/
run;
/*去重*/
proc sql noprint;
create table aa.allword as
select distinct word from aa.allword_temp;
quit;
;
接下來的工作就麻煩了。
/*0-3位縮寫不合格的*/
proc sql noprint;
create table aa.temp2 as
select distinct word,substr(word,1,3) as suox from aa.allword
group by suox
having count(word)>&wait_max. and length(word)>3;
/*0-3位縮寫合格的*/
create table aa.yes2 as
select distinct word,substr(word,1,3) as suox from aa.allword
group by suox
having count(word)<= &wait_max. or length(word)<=3;
quit;
;
測試一下,縮寫成3位,檢查,能正確運行之后,就可以寫宏程序(弄一個循環)
我想弄一個sql里面的循環的,發現sql里面沒有循環結構,反正我搞不懂
/*3位縮寫,不合格的*/
proc sql noprint;
create table aa.temp3 as
select word,substr(word,1,3) as suox from aa.temp2
group by suox
having count(word)>&wait_max. and length(word)>3
;
/*3位縮寫,合格的*/
/*不宜從allword里選,而是從上一步不合格(0-3位縮寫)的數中選*/
create table aa.yes3 as
select word,substr(word,1,3) as suox from aa.temp2
group by suox
having count(word)<=&wait_max. or length(word)<=3
;
quit;
下面就是完整代碼鏈接: