生成候选词不大于5的缩写词库

程序是用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;

下面就是完整代码链接:

百度云链接 

你可能感兴趣的:(生成候选词不大于5的缩写词库)