Hi All, below is the data I have. I am trying to delete all rows of observations with proc_cd = 23 or proc_cd = 34. In addition, if a claim_id had a proc_cd = 23 or a proc_cd = 34, I also want to delete all the other rows associated with that claim_id. Below is the data "want". You see that only claim_id = 2 and claim_id = 5 are left since they never had a proc_cd = 23 or proc_cd = 34.
data have;
input claim_id proc_cd $ value icd $;
cards;
3 23 34 G5601
3 J20 34 J2
3 J2234 34 G5602
3 J22340 34 G5603
2 123 34 G5603
2 12314 34 C
1 23 64 C
12 23 87 C
4 34 98 G5601
4 35 34 asd
5 35 34 G5602
;
run;
data want;
input claim_id proc_cd $ value icd $;
cards;
2 123 34 G5603
2 12314 34 C
5 35 34 G5602
;
run;
data have;
input claim_id proc_cd $ value icd $;
cards;
3 23 34 G5601
3 J20 34 J2
3 J2234 34 G5602
3 J22340 34 G5603
2 123 34 G5603
2 12314 34 C
1 23 64 C
12 23 87 C
4 34 98 G5601
4 35 34 asd
5 35 34 G5602
;
run;
proc sql;
create table want as
select *
from have
where claim_id not in
(select distinct claim_id from have where proc_cd in ('23','34'));
quit;
data have;
input claim_id proc_cd $ value icd $;
cards;
3 23 34 G5601
3 J20 34 J2
3 J2234 34 G5602
3 J22340 34 G5603
2 123 34 G5603
2 12314 34 C
1 23 64 C
12 23 87 C
4 34 98 G5601
4 35 34 asd
5 35 34 G5602
;
run;
proc sql;
create table want as
select *
from have
where claim_id not in
(select distinct claim_id from have where proc_cd in ('23','34'));
quit;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.