- data test;
- input (a b c d e f) ($);
- cards;
- 1 2 3 r t 3
- 3 4 5 d 5 4
- e 没 4 5 b 4
- ;
- run;
- *把字符变量全部找出来,并赋值给宏变量varname;
- proc contents data=test out=type noprint;
- run;
- proc sql noprint;
- select name into :varname separated by " " from type where type=2;
- quit;
- *使用数组,如果满足if,则i就是变量在宏变量varname的排序,num里某变量出现次数即为其里面包含字符观测的个数;
- data test1;
- set test;
- array varchar{*} &varname.;
- do i=1 to dim(varchar);
- if prxmatch("/\d/",varchar(i))=0 then
- do;
- num=scan("&varname.", i, " ");
- output;
- end;
- end;
- keep num;
- run;
- proc sort data=test1 out=test2 nodupkey;
- by num;
- run;
- proc print data=test2;
- run;