Calcite | Level 5

## Calculating patietn days for each month using start and end dates

I have some data in the following format

data testdate;
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
Super User

## Re: Calculating patietn days for each month using start and end dates

``````
data testdate;
format _all_ mmddyy10.;
datalines;
6/29/2019    8/26/2019
12/27/2018   4/3/2019
;
data temp;
set testdate;
n+1;
output;
end;
run;
proc summary data=temp ;
by n date;
format date monyy7.;
output out=want ;
run;``````
3 REPLIES 3
Tourmaline | Level 20

## Re: Calculating patietn days for each month using start and end dates

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

``````
data testdate;
format _all_ mmddyy10.;
datalines;
6/29/2019    8/26/2019
12/27/2018   4/3/2019
;
data want;
set testdate;
do while(d<discharge_date);
month_year=put(d,monyy7.);
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;``````

Super User

## Re: Calculating patietn days for each month using start and end dates

``````
data testdate;
format _all_ mmddyy10.;
datalines;
6/29/2019    8/26/2019
12/27/2018   4/3/2019
;
data temp;
set testdate;
n+1;
output;
end;
run;
proc summary data=temp ;
by n date;
format date monyy7.;
output out=want ;
run;``````
Tourmaline | Level 20

## Re: Calculating patietn days for each month using start and end dates

@Ksharp  slick idea Sir 🙂  Nice and neat!

Discussion stats
• 3 replies
• 648 views
• 4 likes
• 3 in conversation