BookmarkSubscribeRSS Feed
indrakshiroy90
Calcite | Level 5

Hello,

 

I have a dataset with multiple rows per id and I am trying to create episode start and end dates. My data looks as follows:

IDtrgt_dtA1600A1700A1800R4A2100
19-Jun-00.....
114-Jun-002-Jun-0013..
122-Jun-00...22-Jun-001
113-Nov-03.....
119-Nov-036-Nov-0313..
122-Nov-03...22-Nov-031
123-Jan-0716-Jan-0713..
129-Jan-07.....
131-Jan-07...31-Jan-071
11-Feb-07.....
111-Feb-0731-Jan-071311-Feb-073
112-Feb-0712-Feb-0723..
119-Feb-076-Feb-0713..
122-Feb-07.....
15-Mar-07.....
126-Mar-07...26-Mar-071

 

A1600 is the entry/reentry date, A1700 = 1 when its an entry and 2 when its a reentry. R4 is the discharge date. I want to use the dates per ID to create a chronological sequence of events for the patient in terms of start and end of episodes. Sometimes discharge dates can be missing. The desired output would look as follows:

IDtrgt_dtA1600R4stay_entrystay_end
19-Jun-00..2-Jun-00.
114-Jun-002-Jun-00.2-Jun-00.
122-Jun-00.22-Jun-002-Jun-0022-Jun-00
113-Nov-03..6-Nov-03.
119-Nov-036-Nov-03.6-Nov-03.
122-Nov-03.22-Nov-036-Nov-0322-Nov-03
123-Jan-0716-Jan-07.16-Jan-07.
129-Jan-07..16-Jan-07.
131-Jan-07.31-Jan-0716-Jan-0731-Jan-07
11-Feb-07.1-Feb-0731-Jan-071-Feb-07
111-Feb-0731-Jan-0711-Feb-076-Feb-0711-Feb-07
112-Feb-0712-Feb-07.12-Feb-07.
119-Feb-076-Feb-07.12-Feb-07.
122-Feb-07..12-Feb-07.
15-Mar-07..12-Feb-07.
126-Mar-07.26-Mar-0712-Feb-0726-Mar-07



How can I achieve this with sas coding?
Thank you in advance.


3 REPLIES 3
SASJedi
Ammonite | Level 13

I don't have the bandwidth to work on this right now, but here's code to create the HAVE dataset for testing:

data have;
  infile datalines dsd truncover;
  input ID:32. trgt_dt:32. A1600:32. A1700:32. A1800:32. R4:32. A2100:32.;
  format trgt_dt A1600 R4 DATE11.;
datalines4;
1,14770,,,,,
1,14775,14763,1,3,,
1,14783,,,,14783,1
1,16022,,,,,
1,16028,16015,1,3,,
1,16031,,,,16031,1
1,17189,17182,1,3,,
1,17195,,,,,
1,17197,,,,17197,1
1,17198,,,,,
1,17208,17197,1,3,17208,3
1,17209,17209,2,3,,
1,17216,17203,1,3,,
1,17219,,,,,
1,17230,,,,,
1,17251,,,,17251,1
;;;;
Check out my Jedi SAS Tricks for SAS Users
indrakshiroy90
Calcite | Level 5
Thank you @SASJedi. If you are able to give some suggestions later when you get a chance, I would greatly appreciate it.
mkeintz
PROC Star

Please state a clear and complete rule for assigning stay_start and stay_end.  I cannot conjure up a rule to satisfy all the results you show.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

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

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