data have;
input ID Flag;
datalines;
1000 2
1000 1
1000 9
1000 1
1000 5
1000 1
1000 1
1000 1
1000 1
2000 11
2000 12
2000 4
2000 1
2000 1
2000 3
2000 1
2000 1
2000 1
;
run;
data want;
do until(last.flag);
set have;
by id flag notsorted;
if last.id then found=1;
end;
do until(last.flag);
set have;
by id flag notsorted;
if found and flag=1 then output;
end;
drop found;
run;
The 2025 SAS Hackathon has begun!
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.