I received a request where the customer wants me to show how many hours the patient stayed in each month.
Here is an example:Patient was here January 1st 2:00 pm and discharge February 2nd 1:00AM
Should become like this:
January: 730 hours (10 hours on January 1st + 30 days *24 hours per day)
February 25 hours (24 hours on February 1st and 1 hour on February 2nd).
If you cannot figure out a way, I would be greatly appreciated if you can at least provide me information how to calculate the number of hours patient stayed on first and last day (10 hours on January 1st and 1 hour on February 2nd). I have a way to calculate the hours between January 2nd and February 1st. I am having problems in getting the hours to midnight for first day and midnight to discharge datetime for the last day
I tried intck with 'end', 'b' but I keep getting error messages.
Here is sample of the checkin and checkout datetime
CheckinDate: 01JAN2014:2:00:00PM
CheckoutDate: 02FEB2014:1:00:00AM
THis is a followup after this post I have posted
This time the requester wants number of hours instead of number of days each month.
data want (keep=yymm hours);
set have;
start = checkin;
yymm = year(datepart(checkin))*100 + month(datepart(checkin));
yymmend = year(datepart(checkout))*100 + month(datepart(checkout));
do while(yymm < yymmend);
hours = round((intnx('dtmonth',start,0,'end') - start) / 3600,1);
output;
start = intnx('dtmonth',start,1,'begin');
yymm = year(datepart(start))*100 + month(datepart(start));
end;
hours = round((checkout - start) / 3600,1);
output;
run;
data temp;
CheckinDate= '01JAN2014:2:00:00PM'dt;
CheckoutDate= '02FEB2014:1:00:00AM'dt;
i=CheckinDate;
do while(i lt CheckoutDate);
date=datepart(i); output;
i+3600;
end;
run;
proc summary data=temp nway;
class date;
format date monyy7.;
output out=want(drop= _type_ rename=(_freq_=hours)) ;
run;
Xia Keshan
Hi thank you for your help Xia.
When I tried with checkin date time April 4, 2014 17:25 and checkout datetime April 30, 2014 23:59 the hours are a bit off.
Using the code above I got 635 hours.
I used this website to do the calculation and it came with 630 hours not sure what they meant by rounding down.
Here is the timestamp but I don't think it should matter since the area and visit_number is the same.
Checkin Date/Time | Checkout Date/Time |
4/4/2014 17:25 | 4/14/2014 11:08 |
4/14/2014 11:08 | 4/14/2014 11:10 |
4/14/2014 11:10 | 4/16/2014 10:44 |
4/16/2014 10:44 | 4/21/2014 8:12 |
4/21/2014 8:12 | 4/23/2014 14:35 |
4/23/2014 14:35 | 4/27/2014 16:47 |
4/27/2014 16:47 | 4/29/2014 21:38 |
4/29/2014 21:38 | 5/3/2014 0:15 |
If you can reduce the data to one pair of checkin / checkout SAS datetime variables then
Hours = (checkout - checkin)/3600; Which will likely have a decimal component.
Your DateTime value is not right .
data temp;
CheckinDate= '04apr2014:17:25:00'dt;
CheckoutDate= '30apr2014:23:59:59'dt;
i=CheckinDate;
do while(i lt CheckoutDate);
date=datepart(i); output;
i+3600;
end;
run;
proc summary data=temp nway;
class date;
format date monyy7.;
output out=want(drop= _type_ rename=(_freq_=hours)) ;
run;
data want (keep=yymm hours);
set have;
start = checkin;
yymm = year(datepart(checkin))*100 + month(datepart(checkin));
yymmend = year(datepart(checkout))*100 + month(datepart(checkout));
do while(yymm < yymmend);
hours = round((intnx('dtmonth',start,0,'end') - start) / 3600,1);
output;
start = intnx('dtmonth',start,1,'begin');
yymm = year(datepart(start))*100 + month(datepart(start));
end;
hours = round((checkout - start) / 3600,1);
output;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.