/* 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
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.