/* 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
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.