以SASHELP.CLASS数据为例,以sex变量分组对变量weight进行分别累加,程序如下,但是没有达到要求,错在哪里?
- data class; set sashelp.class; run;
- proc sort data=class; by sex; run;
- data test;
- set class;
- by sex;
- if first.sex then do;
- cum_weight=weight;
- cut_weight=1;
- avg_weight=.;
- end;
- cum_weight=cum_weight+weight;
- cut_weight=cut_weight+1;
- avg_weight=cum_weight/cut_weight;
- run;
- proc print data=test; run;
结果