Have not reviewed/replied SAS programming threads for fun in recent years. This one is an interesting fun topic to practice all basic DATA step statement elements. data have;
input id value;
datalines;
1 1
1 .
1 1
1 .
1 1
1 .
1 .
1 .
1 .
1 .
1 .
1 -1
1 .
1 -1
1 .
1 .
1 1
1 1
2 -1
2 .
2 1
2 .
2 1
;
data ahuige(keep=id value count);
do obsnum=1 to last;
set have nobs=last;
count=sum(0,sign(value));
over=0;
do point=obsnum+1 to obsnum+5;
if point<=last and not over then
do;
set have(rename=(id=nowId value=nowValue)) point=point;
over=((id ne nowId) or sign(NowValue)*sign(count)=-1 );
if not over then count=sum(count,sign(NowValue)) ;
end;
end;
output;
end;stop;
run;
proc print;run;;
... View more