SAS中文论坛
标题:
sum的问题求助
[打印本页]
作者:
shiyiming
时间:
2012-4-17 05:07
标题:
sum的问题求助
data temp;
input id y;
cards;
1 104.932
2 107.732
3 103.121
4 103.340
5 104.653
6 101.401
7 95.430
8 98.784
9 102.981
10 98.921
11 94.178
12 90.831
13 98.756
14 93.079
15 99.559
16 99.036
17 98.258
18 90.956
19 89.173
20 89.344
run;
我想做的就是
对于第i个id,算出sum=sum_{yj>yi}(yj )
我能想到的就是用do loop,但是结果不对
这个要怎么做呢?
作者:
shiyiming
时间:
2012-4-21 19:41
标题:
Re: sum的问题求助
下面是不是你要的结果:
data temp;
input id y;
cards;
1 104.932
2 107.732
3 103.121
4 103.340
5 104.653
6 101.401
7 95.430
8 98.784
9 102.981
10 98.921
11 94.178
12 90.831
13 98.756
14 93.079
15 99.559
16 99.036
17 98.258
18 90.956
19 89.173
20 89.344
;
run;
%macro sm;
%let nfile=%sysfunc(open(temp));
%let nrw=%sysfunc(attrn(&nfile,nlobs));
%let rc=%sysfunc(close(&nfile));
proc iml;
use work.temp;
read all into mx;
nrw=nrow(mx);
%do i = 1 %to &nrw;
s=0;
m1=mx[&i,2];
%do j=1 %to &nrw;
m2=mx[&j,2];
if (m2>m1) then do;
s=s+m2;
end;
print s;
%end;
%end;
quit;
%mend;
%sm;
欢迎光临 SAS中文论坛 (http://www.mysas.net/forum/)
Powered by Discuz! X3.2