全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1344 2
2011-07-26
The same problem can be solved with SQL. But it may have a performance issue.

A data step is much faster.

Replacing  tmpy[i]=1e308;  ---> tmpy[i]=-1e308;
and min=tmpy[1];  ---> max=tmpy[&k];

will get max in the previous k rows in each group.



%let group=20000;
%let maxn=1000;
%let k=200;
data t1;
   do g=1 to &group;
        n=ceil(ranuni(123)*&maxn);
  do i=1 to n;
  x=ceil(rannor(123)*&maxn);
     output;
  end;
end;
keep g x;
run;
data t2;
  array tmpx(10000) _temporary_ ;
  array tmpy(&k) _temporary_ ;
do until(last.g);
   set t1;
   by g;
   if first.g then cnt=0;
   cnt+1 ;
   tmpx[cnt]=x;
   k=0;
   do i=1 to &k;
     tmpy[i]=1e308;
   end;
   do i=max(cnt-&k+1,1) to cnt;
     k+1;
     tmpy[k]=tmpx[i];
  *put tmpy[k]=;
   end;
   call sortn(of tmpy[*]);
   min=tmpy[1];
   output;
end;
keep x g min;
run;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2011-7-26 11:26:05
数据量好大。。。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2011-7-26 22:42:15
honghejing 发表于 2011-7-26 11:26
数据量好大。。。
Taking away some zeros from 3 macro variabels will reduce the amount od data.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群