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

I have some data in the following format

 

data testdate;
   input admit_date discharge_date;
   date = input(chardate,yymmdd10.);
return;
datalines;

6/29/2019    8/26/2019

12/27/2018   4/3/2019

 

;

 

 

I need to determine the number of patient days someone was admitted per month.  For example,for the first row there would be 1 day for June 2019, 31 for July 2019, and 26 for August 2019.  I have about 800 records and would love a way to automate this if possible.  Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
  
data testdate;
   input admit_date :mmddyy10. discharge_date :mmddyy10.;
   format _all_ mmddyy10.;
datalines;
6/29/2019    8/26/2019
12/27/2018   4/3/2019
;
data temp;
 set testdate;
 n+1;
 do date=admit_date+1 to discharge_date;
  output;
 end;
run;
proc summary data=temp ;
by n date;
format date monyy7.;
output out=want ;
run;

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20

Hello @simkinm2  You didn't show us your expected output structure, but the logic is clear though

 

  
data testdate;
   input admit_date :mmddyy10. discharge_date :mmddyy10.;
   format _all_ mmddyy10.;
datalines;
6/29/2019    8/26/2019
12/27/2018   4/3/2019
;
data want;
set testdate;
d =admit_date;
do while(d<discharge_date);
 month_year=put(d,monyy7.);
 if month(d)=month(admit_date) then days=intnx('mon',d,0,'e')-d+1;
 else if month(d)=month(discharge_date) then days=day(discharge_date);
 else days=day(intnx('mon',d,0,'e'));
 output;
 d=intnx('mon',d,1);
end;
drop d;
run;

 

 

Ksharp
Super User
  
data testdate;
   input admit_date :mmddyy10. discharge_date :mmddyy10.;
   format _all_ mmddyy10.;
datalines;
6/29/2019    8/26/2019
12/27/2018   4/3/2019
;
data temp;
 set testdate;
 n+1;
 do date=admit_date+1 to discharge_date;
  output;
 end;
run;
proc summary data=temp ;
by n date;
format date monyy7.;
output out=want ;
run;
novinosrin
Tourmaline | Level 20

@Ksharp  slick idea Sir 🙂  Nice and neat!

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!
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
  • 3 replies
  • 651 views
  • 4 likes
  • 3 in conversation