我想用两个循环来做来着,可是总是出错,我是这么编的
data a;
input x1-x100@@;
array x[100] x1-x100;
a=mean(of x1-x100);
k=2;
do t=2 to 100;
do i=0 to k-1;
b+y[t-i]; /*b表示括号内的y(t)+y(t-1)+y(t-2)+.....+y(t-k+1)*/
end;
c+(b-a*2)**2; /*c表示总的和*/
end;
cards;
......
问题在于 算的总是不对 跪求大家帮帮我.......作者: shiyiming 时间: 2010-7-1 18:03 标题: Re: 关于一个循环求和的问题 Hope the following is waht you want:
data a;
input x1-x5;
array x[5] x1-x5;
a=mean(of x1-x5);
k=2;
do t=2 to 5;
do i=0 to k-1;
b+x[t-i];
end;
c+(b-a)**2;
b=0;
end;
drop t i;
cards;
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
;
run;
/* set b=0 after inner loop, or b value will be cumulated in each loop */