|
|
沙发

楼主 |
发表于 2009-12-11 17:52:15
|
只看该作者
Re: 关于'retain'
个人认为斑竹的SQL是最佳的方法,不推荐retain
[code:x2myd2sl]data raw;
input group $ x y;
datalines;
a 1 5
a 7 10
a 8 10
b 5 10
b 10 22
b 11 21
b 16 25
c 1 5
d 2 6
d 7 9
d 10 20
d 11 12
d 13 15
d 15 23
e 1 3
f 2 7
f 9 11
;
data temp(drop=max_n n);
retain max_n;
n=0;
do _n_=1 by 1 until(last.group);
set raw end=eof;
by group;
n+1;
output;
end;
max_n=max(max_n,n);
if eof then call symputx('n',max_n);
run;
data temp(keep=group x y flag);
array arr{2,&n} x1-x&n y1-y&n;
do _n_=1 by 1 until(last.group);
set temp;
by group;
flag=0;
arr(1,_n_)=x;
arr(2,_n_)=y;
do i=1 to &n;
if arr(1,i)<=x<=arr(2,i) then flag+1;
end;
flag=flag-1;
output;
end;
run;[/code:x2myd2sl] |
|