BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
NewUsrStat
Lapis Lazuli | Level 10

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

1 ACCEPTED SOLUTION

Accepted Solutions
quickbluefish
Barite | Level 11
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

View solution in original post

5 REPLIES 5
quickbluefish
Barite | Level 11
data DB1;
set DB;
WHERE discharge>admission;
run;

You could also use:

discharge^=admission

 

NewUsrStat
Lapis Lazuli | Level 10

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.

quickbluefish
Barite | Level 11
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

Ksharp
Super User
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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 5 replies
  • 1911 views
  • 1 like
  • 3 in conversation