BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
BlairWitty
Calcite | Level 5

Hello all,

 

I currently have a dataset in which each row represents one patient and includes data on their admission and discharge dates to the hospital. I ultimately need the dataset to include 1 row for each patient for each week they were admitted. For example, if a patient was in hospital for weeks 1-4 of 2020 they would have a row for week 1, week 2, week 3, and week 4. 

 

I have been getting nowhere close with code attempts. But know that if Week of Admission is not equal to Week of Discharge I need the number of new rows generated to be the difference between the two. Any help is greatly appreciated!

 

 

Current Data Structure

Patient IDWeek of AdmissionWeek of Discharge
111
224
313
468

 

Desired Data Structure (New columns and rows highlighted in green text)

Patient IDHospital weekWeek of AdmissionWeek of Discharge
1111
2224

2

3  
24  
3 113
32  
33  
4 668
47  
48  
1 ACCEPTED SOLUTION

Accepted Solutions
japelin
Rhodochrosite | Level 12

Which results do you want?

japelin_0-1652314672910.png

 

Are you sure you want the results of Want2?

data have;
  input Patient_ID	Week_of_Admission	Week_of_Discharge;
datalines;
1	1	1
2	2	4
3	1	3
4	6	8
;
run;

data want;
  set have;
  do Hospital_week=Week_of_Admission to Week_of_Discharge;
    output;
  end;
run;

data want2;
  set have;
  si=Week_of_Admission;
  ei=Week_of_Discharge;
  Hospital_week=Week_of_Admission;
  output;

  do Hospital_week=si+1 to ei;
    Week_of_Admission=.;
    Week_of_Discharge=.;
    output;
  end;
  drop si ei;
run;

 

View solution in original post

3 REPLIES 3
japelin
Rhodochrosite | Level 12

Which results do you want?

japelin_0-1652314672910.png

 

Are you sure you want the results of Want2?

data have;
  input Patient_ID	Week_of_Admission	Week_of_Discharge;
datalines;
1	1	1
2	2	4
3	1	3
4	6	8
;
run;

data want;
  set have;
  do Hospital_week=Week_of_Admission to Week_of_Discharge;
    output;
  end;
run;

data want2;
  set have;
  si=Week_of_Admission;
  ei=Week_of_Discharge;
  Hospital_week=Week_of_Admission;
  output;

  do Hospital_week=si+1 to ei;
    Week_of_Admission=.;
    Week_of_Discharge=.;
    output;
  end;
  drop si ei;
run;

 

BlairWitty
Calcite | Level 5
Either option is great, thank you so much! I was clearly overthinking this and making it much more complicated!

Thank you!
ballardw
Super User

Before using "week" for anything you may want to provide what your definition of "week" is. Does it have a fixed day of the week to start? If so which day of the week is it? Or is are you wanting 7-day intervals starting on the first date encountered?

Also, you don't show any actual dates. Working with dates is likely to make this much more approachable if you want to split anything up.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 340 views
  • 0 likes
  • 3 in conversation