/* 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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.