turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- How many hours each month

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-17-2015 01:22 AM

I received a request where the customer wants me to show how many hours the patient stayed in each month.

Here is an exampleatient 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.

Accepted Solutions

Solution

05-20-2015
01:59 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-20-2015 01:59 AM

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;

---------------------------------------------------------------------------------------------

Maxims of Maximally Efficient SAS Programmers

Maxims of Maximally Efficient SAS Programmers

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-18-2015 08:44 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-19-2015 10:27 AM

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 |

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-19-2015 12:49 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-20-2015 08:19 AM

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;

Solution

05-20-2015
01:59 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-20-2015 01:59 AM

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;

---------------------------------------------------------------------------------------------

Maxims of Maximally Efficient SAS Programmers

Maxims of Maximally Efficient SAS Programmers