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;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.