BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
mayasak
Quartz | Level 8

Hi,

 

I have a data set and a death list. I need to remove the dead cases from the original dataset and keep the living observations. I would greatly appreciate your help to delete the dead observations from the original dataset. 

data have;
input ID Name$ City$ State$;
cards;
11321 Mickey Mouse Miami FL
44555 Alice Meek Baltimore MD
21713 Lili Good Atlanta GA
12346 Donald Duck Houston TX
;
run;

Death list:
44555 Alice Meek Baltimore MD
21713 Lili Good Atlanta GA

Wanted list:
11321 Mickey Mouse Miami FL
12346 Donald Duck Houston TX

 

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Data step solution which does not need any prior sorting:

data want;
set have;
if _n_ = 1
then do;
  declare hash d (dataset:"death");
  d.definekey("id");
  d.definedone();
end;
if d.check() ne 0;
run;

View solution in original post

3 REPLIES 3
Ksharp
Super User
data have;
input ID Name & $20. City$ State$;
cards;
11321 Mickey Mouse   Miami FL
44555 Alice Meek     Baltimore MD
21713 Lili Good      Atlanta GA
12346 Donald Duck    Houston TX
;
run;

data Death ;
input ID Name & $20. City$ State$;
cards;
44555 Alice Meek   Baltimore MD
21713 Lili Good    Atlanta GA
;
run;

proc sql;
create table want as
select * from have
except
select * from Death
;
quit;
Kurt_Bremser
Super User

Data step solution which does not need any prior sorting:

data want;
set have;
if _n_ = 1
then do;
  declare hash d (dataset:"death");
  d.definekey("id");
  d.definedone();
end;
if d.check() ne 0;
run;
mayasak
Quartz | Level 8
Thank you Kurt. This was helpful.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1187 views
  • 0 likes
  • 3 in conversation