Here is a datastep solution:
data have;
input claim $ id;
cards;
001 1
001 2
001 4
002 1
002 3
002 5
;run;
data want;
set
have(where=(id not in(1,4)))
have(where=(id=1) in=in1)
have(where=(id=4) in=in4)
;
by claim;
if in1 and not last.claim then
id=0;
if in4 and lag(id)=0 then
delete;
run;You may want to sort by claim and id afterwards, as the zeros, ones and fours are now last in the output.
data have;
input claim $ id;
cards;
001 1
001 4
;
proc sql;
create table want as
select distinct claim, id not in (1,4) as id
from have
having id=0;
quit;
Here is a datastep solution:
data have;
input claim $ id;
cards;
001 1
001 2
001 4
002 1
002 3
002 5
;run;
data want;
set
have(where=(id not in(1,4)))
have(where=(id=1) in=in1)
have(where=(id=4) in=in4)
;
by claim;
if in1 and not last.claim then
id=0;
if in4 and lag(id)=0 then
delete;
run;You may want to sort by claim and id afterwards, as the zeros, ones and fours are now last in the output.
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 how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.