如何计算SAS中变量值的频率

时间:2013-10-19 18:53:30

标签: count sas frequency

以下是我的数据:

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表示每个ID

的值列中显示的时间1

1 个答案:

答案 0 :(得分: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;