0

这是我拥有的数据:

ID VALUE
1    1
2   -1
3    1
4    1
5    1
1    1
2    1
3   -1
4    1
5   -1
...

我怎样才能得到这样的表:

ID value=1  value=-1
1    2         0 
2    1         1
3    1         1
4    2         0
5    1         1

value=1表示1每个 ID 在值列中出现的次数

4

1 回答 1

1
data work.indata    ;
input ID VALUE;
cards;  
1    1
2   -1
3    1
4    1
5    1
1    1
2    1
3   -1
4    1
5   -1
;
run;

/*    
proc sort data=work.indata;
by ID;
run;
*/

proc freq noprint data=work.indata;
tables ID * VALUE /out=WORK.COUNTS nopercent ;
run;


proc transpose data=WORK.COUNTS out=work.output (drop=_name_ _label_);
id value;
by id;
var count;
run;
于 2013-10-19T19:27:18.543 回答