Dear all,
suppose to have the following:
data DB;
input ID :$20. Admission :date09. Discharge :date09.;
format Admission date9. Discharge date9.;
cards;
0001 13JAN2015 13JAN2015
0001 13JAN2015 31MAR2015
0001 01MAR2018 30SEP2018
0001 01JAN2019 31DEC2019
0002 01JAN2015 31DEC2015
0002 01JAN2019 01JAN2019
0002 01JAN2019 15APR2019
;
Is there a way to get the following?
data DB1;
input ID :$20. Admission :date09. Discharge :date09.;
format Admission date9. Discharge date9.;
cards;
0001 13JAN2015 31MAR2015
0001 01MAR2018 30SEP2018
0001 01JAN2019 31DEC2019
0002 01JAN2015 31DEC2015
0002 01JAN2019 15APR2019
;
In other words for equal admission dates I would like to remove the rows where admission == discharge and retain all the cases where admission =! discharge. The first case occurs because there is an emergency department access while the second is a real admission.
Can anyone help me please?
Best
proc sort data=DB; by ID admission; run;
data DB1;
set DB;
by ID;
if (first.ID=1 and last.ID=1) or discharge>admission;
run;
This will keep records in EITHER of these two cases:
- 1. person has only one record
- 2. discharge is greater than admission
data DB1;
set DB;
WHERE discharge>admission;
run;
You could also use:
discharge^=admission
Thank you for your help. Unfortunately there are also cases where admission=discharge and no other admissions occur for that patient. The way you suggest would remove that cases.
proc sort data=DB; by ID admission; run;
data DB1;
set DB;
by ID;
if (first.ID=1 and last.ID=1) or discharge>admission;
run;
This will keep records in EITHER of these two cases:
- 1. person has only one record
- 2. discharge is greater than admission
data DB;
input ID :$20. Admission :date09. Discharge :date09.;
format Admission date9. Discharge date9.;
cards;
0001 13JAN2015 13JAN2015
0001 13JAN2015 31MAR2015
0001 01MAR2018 30SEP2018
0001 01JAN2019 31DEC2019
0002 01JAN2015 31DEC2015
0002 01JAN2019 01JAN2019
0002 01JAN2019 15APR2019
;
data temp;
set DB;
do date= Admission to Discharge ;
output;
end;
keep ID date;
format date date9.;
run;
proc sort data=temp nodupkey;by id date;run;
data temp2;
set temp;
by id;
if first.id or dif(date) ne 1 then group+1;
run;
proc summary data=temp2;
by group id;
var date;
output out=want(drop=_:) min=Admission max=Discharge;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.