一拆多 验证打标

data a;
input id$ aa$ bb;
cards;
3 1 da
3 2 22
1 1 123
1 2 113
2 1 22
2 2 33
;
run;


/*笨办法,按照分类标志取子表,几个分类就取几张*/
data a1;
set a;
rename aa=a1
bb=b1;
if aa="1";
run;
proc sort data=a1;
by id;
run;
data a2;
set a;
rename aa=a2 bb=b2;
if aa="2";
run;
proc sort data=a2;
by id;
run;
/*再merge分表*/
data aa;
merge a1 a2;
by id;
run;




/*一招搞定*/
proc sort data=a;by id ;run;
proc transpose data=a out=aaaa(drop=_:) prefix=value_;
by id;  /*主键*/
var bb; /*需要分类的变量*/
run;






/*测试*/
data test1;
input id$ a3$;
cards;
1 123
1 2
1 244
1 455
2 22
2 2323
2 4355
3 da
3 22 
;
run;


/*test2的a3用来检验,如果在aaaa总则打标y=1*/
data test2;
merge test1(in=t1)
aaaa;
by id;
if t1;
if a3=value_1 or a3=value_2 then y="1" ;
else y="0";
run;

你可能感兴趣的:(sas)