sas proc means可以直接分组求统计量。下面演示的是用data步分组求和:
data x;
input id age;
cards;
1 13
1 41
1 12
2 41
2 52
2 12
3 12
3 4
;
run;
首先对数据进行排序,因为后面的by语句要用到
proc sort data = x;
by id;
run;
data m3;
set x;
by id;
if first.id then tot = 0;
tot + age;
if first.id then time = 0;
time + 1;
mean = tot / time;
run;
结果如下: