data sa;
input comments $ category $40.;
cards;
d1 ctt,avv
d2 avv
d3 ctt,avv
d4 gdd
d5 ctt,avv,gdd
d6 avv
d7 ctt
;
data x;
input cate $ @@;
cards;
ctt avv gdd
;
option mprint mlogic symbolgen;
%macro s(n);
data _null_;
set x;
call symput(left(compress('cat'||_n_)),trim(cate));
data r;set sa;
%do i=1 %to &n;
y&i=left(trim(scan(category,&i,',')));
%do t=1 %to &n;
if y&i = "&&cat&t" then &&cat&t=1;
%end;
%end;
%do x=1 %to &n;
if &&cat&x=. then &&cat&x=0;
%end;
drop y1-y&n;
run;
%mend;
%s(3);
我的这个code有个缺点,必须先把所有category的具体值先输入进去,存成变量。
还有n多的循环。。。唉,编程真是痛苦。。
[此贴子已经被作者于2009-6-9 11:12:51编辑过]