/* test data */
data one;
input name $ no sl $ cnt;
cards;
Bob 35 a20 1
Bob 44 a22 2
Bob 28 a20 3
John 35 a20 1
John 35 a22 2
John 35 a20 3
John 35 a20 4
John 35 a22 5
;
run;
/* removes obs whose cnt is one less than the next one with sl="a22" */
data two;
dcl hash h();
h.defineKey('cnt');
h.defineDone();
do until (last.name);
set one;
by name cnt;
if sl="a22" then do;
cnt = cnt - 1;
h.add();
end;
end;
do until (last.name);
set one;
by name cnt;
if h.check(key:cnt)=0 then continue;
output;
end;
h.clear();
run;
proc print data=two;
run;
/* on lst
Obs name no sl cnt
1 Bob 44 a22 2
2 Bob 28 a20 3
3 John 35 a22 2
4 John 35 a20 3
5 John 35 a22 5
*/
Another one is based on reading same data twice:
Marius
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.