我想在SAS中进行迭代循环,以计算每个id我的数据的平均值如下:
答案 0 :(得分:0)
在SAS数据步骤中,您使用do
循环进行迭代处理https://blogs.sas.com/content/iml/2011/09/07/loops-in-sas.html。
但是,为了获得每个想法的平均值,SQL通常要简单得多。
proc sql;
select id, mean(value)
from data
group by id
;
quit;
答案 1 :(得分:0)
data begin;
input id value;
cards;
1 10
1 20
1 5
2 9
2 6
3 50
3 20
3 44
3 79
; run;
proc sort data=begin; by id; run; /*This is not needed in our case, but it is good practice to always sort in SAS.*/
proc means data=begin;
by id; /*These are variables you count by*/
var value; /*The value you count the mean by. You also get additional values. */
run;
您也可以用 mean(value)= my_mean
替换var(mean)