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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.