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
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;
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;
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;
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.