BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
advmsj
Obsidian | Level 7

Happy weekend, I am trying to find the time to readmission (last column). I ordered my data by ID and I wish to find the time from the previous hospital discharge to the next readmission. For example. for ID 1, I would like to know the time between 01/30/17 and 03/27/19, and 04/10/19 and 07/02/20. I am unsure of how to do this in SAS. Any help is appreciated

 

ID

BirthDate

Admit Date

Discharge Date

Times ill

Time to readmission

1

12/07/95

01/01/17

01/30/17

1

 

1

12/07/95

03/27/19

04/10/19

2

 

1

12/07/95

07/02/20

07/25/20

3

 

2

12/24/99

03/13/16

03/27/16

1

 

2

12/24/99

10/20/19

11/03/19

2

 

3

07/26/98

05/10/17

05/30/17

1

 

4

09/29/82

06/30/18

 

1

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

data have;
input ID	(BirthDate	Admitdate	DischargeDate) (:mmddyy10.)	Timesill;
format BirthDate	Admitdate	DischargeDate mmddyy10.;
cards;
1	12/7/1995	1/1/2017	1/30/2017	1
1	12/7/1995	3/27/2019	4/10/2019	2
1	12/7/1995	7/2/2020	7/25/2020	3
2	12/24/1999	3/13/2016	3/27/2016	1
2	12/24/1999	10/20/2019	11/3/2019	2
3	7/26/1998	5/10/2017	5/30/2017	1
4	9/29/1982	6/30/2018		.	1
;

data want;
 do until(last.id);
  set have;
  by id;
  if not first.id then Timetoreadmission=Admitdate-_n_;
  _n_=DischargeDate;
  output;
 end;
run;

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

UNTESTED CODE (If you want tested code, please provide the data as a SAS data step)

 

data want;
    set have;
    by id;
    prev_discharge=lag(discharge_date);
    if not first.id then time_to_readmission=admit_date-prev_discharge;
    else time_to_readmission=.;
    drop prev_discharge;
run;
 

 

--
Paige Miller
novinosrin
Tourmaline | Level 20

data have;
input ID	(BirthDate	Admitdate	DischargeDate) (:mmddyy10.)	Timesill;
format BirthDate	Admitdate	DischargeDate mmddyy10.;
cards;
1	12/7/1995	1/1/2017	1/30/2017	1
1	12/7/1995	3/27/2019	4/10/2019	2
1	12/7/1995	7/2/2020	7/25/2020	3
2	12/24/1999	3/13/2016	3/27/2016	1
2	12/24/1999	10/20/2019	11/3/2019	2
3	7/26/1998	5/10/2017	5/30/2017	1
4	9/29/1982	6/30/2018		.	1
;

data want;
 do until(last.id);
  set have;
  by id;
  if not first.id then Timetoreadmission=Admitdate-_n_;
  _n_=DischargeDate;
  output;
 end;
run;

SAS Innovate 2025: Register Now

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!

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
  • 2 replies
  • 640 views
  • 2 likes
  • 3 in conversation