楼主: fyfzhdsfdx
8455 13

sas每6个数据求均值 [推广有奖]

11
fyfzhdsfdx 发表于 2013-5-12 12:58:29
yongyitian 发表于 2013-5-12 10:34
/* it depends on the maximum value of the random number generated each time */
/* be carefull when  ...
十分感谢,在您代码的帮助下,我应该达到目的了,代码如下:
data a;
do until ((mean>3) or (mean<-3));
s=0; y=0;do j=1 to 6;x=rannor(0); y=0.7*y+x;s+y;mean=s/6;output;end;
end;
run;

12
jolterheadmmtt 发表于 2013-8-5 16:07:59
mark

13
ECNU_zf 发表于 2013-8-6 14:57:30
data c;
input x y $;
cards;
1990             x
1990            y
1990             z
1991             m
1991             s
1992               n
1992          o
1993           p
1993           q
1993           r
1994            s
;
run;
proc sort data=c;
by x;
run;
data want;
set c;by x;
retain id 0;
id+1;
if first.x then id=1;
run;

14
ECNU_zf 发表于 2013-8-6 14:57:59
data d;
input x @@;
cards;
1 2 3 4 5 6
7 8 9 10 11
12 13 14 15
16 17 18
;
run;
data want;
set d;
n=_n_;
retain id 0;
if mod(n,6)=1 then id=(n-1)/6+1;
run;
proc sql;
create table mydata as
select x,n,id,mean(x) as meanx
from want
group by id
;
quit;run;
proc sort data=mydata;
by n;
run;
data mydata;
set mydata;
keep x meanx;
run;

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-31 15:37