标题: 求助sas 一列中0之间取最大值 [打印本页] 作者: shiyiming 时间: 2010-5-4 13:53 标题: 求助sas 一列中0之间取最大值 求助在sas 里如何在一列中 0中间取最大值
0
1
2
3
0
0
1
2
0
中间取最大值3、2作者: shiyiming 时间: 2010-5-4 21:17 标题: Re: 求助sas 一列中0之间取最大值 [code:1xg7lvld]data a;
input x@@; datalines;
0 1 3 2 0 0 1 2 0
;
data b;
set a;
if x = 0 then n+1;
run;
data c;
do until(last.n);
set b; by n;
if x > y then y = x;
end;
do until(last.n);
set b; by n;
z = ifn(x ^= 0, y, 0);
output;
end;
drop n y;
run;[/code:1xg7lvld]作者: shiyiming 时间: 2010-5-5 22:05 标题: Re: 求助sas 一列中0之间取最大值 谢谢 jingju11 , 解决了我的问题,高手阿作者: shiyiming 时间: 2010-5-6 08:24 标题: Re: 求助sas 一列中0之间取最大值 to jingju11, why not do it within one pass of the data?
data b;
set a;
retain zero 0;
retain maxi -9999999;
if x^=0 then maxi=max(maxi, x);
else do;
if mod(zero, 2)=1 then output;
keep maxi;
maxi=-constant('BIG'); zero+1;
end;
run;
[/code:3heasua2]作者: shiyiming 时间: 2010-5-6 16:50 标题: Re: 求助sas 一列中0之间取最大值 搅和一下
[code:j2t4m8zg]data b(keep=max);
set a end=last ;
retain Max;
if x+lag(x)=0 or last then output;
max=ifn(x+lag(x),max(x,max),x);
run;[/code:j2t4m8zg]作者: shiyiming 时间: 2010-5-6 21:03 标题: Re: 求助sas 一列中0之间取最大值 you are right. both of your codes are much more concise than mine. on the other hand, the outputs are slight different.
[u:13i06l6r]yours[/u:13i06l6r]
Obs Max
1 3
2 2