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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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;

View solution in original post

5 REPLIES 5
Ksharp
Super User

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

Vortex
Calcite | Level 5

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.

http://www.timeanddate.com/date/durationresult.html?m1=4&d1=4&y1=2014&m2=4&d2=30&y2=2014&h1=17&i1=25...

Here is the timestamp but I don't think it should matter since the area and visit_number is the same.

Checkin Date/TimeCheckout Date/Time
4/4/2014 17:254/14/2014 11:08
4/14/2014 11:084/14/2014 11:10
4/14/2014 11:104/16/2014 10:44
4/16/2014 10:444/21/2014 8:12
4/21/2014 8:124/23/2014 14:35
4/23/2014 14:354/27/2014 16:47
4/27/2014 16:474/29/2014 21:38
4/29/2014 21:385/3/2014 0:15
ballardw
Super User

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.

Ksharp
Super User

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;

Kurt_Bremser
Super User

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

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.

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
  • 5 replies
  • 1355 views
  • 4 likes
  • 4 in conversation