BookmarkSubscribeRSS Feed
chuie
Quartz | Level 8

Hi All,

I am struggling in  calculation actual length of stay which is given by days in between arrival date/time and discharge date time. I want to incorporate the time  also  as opposed to just calculating  days.

So for example  arrival datetime = 01/01/2019 7am  and discharge date time = 01/03/2019 9pm

so the actual length of stay should be 2 days and 14 hours 

I cannot upload the data due to privacy reason but attached  is the data set screenshot.

 

Thank you so much in advance

 

best,

C

dates.PNG

9 REPLIES 9
PeterClemmensen
Tourmaline | Level 20

So how do you want the length of stay to be displayed in your desired data set? As a decimal number or as '2 days and 14 hours' or?

chuie
Quartz | Level 8

As a decimal like 12 hours if 3.5 days? or any standard format of actual LOS . I am not sure. My plan is to calculate the variance between GMLOS and Actual LOS . 

PaigeMiller
Diamond | Level 26
data want;
    set have;
    delta_time=new_admit-new_dis;
    days = floor(delta_time/86400);
    hours = floor((delta_time-days*86400)/3600);
    minutes = floor((delta_time-days*86400-hours*3600)/60);
run;
--
Paige Miller
Astounding
PROC Star

DateTimes make this easy:

 

number_of_seconds = new_dis - new_admit;

 

If you want to convert that to hours, divide by 3600.

 

It should be relatively easy to convert number of hours into any form that you would like.

PeterClemmensen
Tourmaline | Level 20
data test;
arrival='01jan2019 07:00:00'dt;
discharge='03jan2019 21:00:00'dt;

time=discharge-arrival;

format arrival discharge datetime20.;
run;
chuie
Quartz | Level 8

YOU guys are AWESOME ... 

Thank you 🙂

one more question:

How to calculate "average patient per hour"

I have patients account number  and  admit date/time for entire 2018 year 

PeterClemmensen
Tourmaline | Level 20

Show us what your data looks like for a usable code answer

chuie
Quartz | Level 8

 I have  encounter number , admit date and admit hour for entire 2018 data ( n = 55000) where each row represents the  unique patient encounter.  I need to calculate the average patient per hour .average.PNG

mkeintz
PROC Star

There is an alternative (or perhaps call it an extension) to dividing by number of seconds, minutes, hours, etc - namely a format that displays something like

     20D:12:30

which means 20 days, 12 hours, 30 minutes

 

proc format;
  picture fdur 
   low-high=  '%jD%0H:%0M' (datatype=datetime);
run;

data want;
  set have;
  duration=discharge-arrival;
  format duration fdur.;
run;

 

Caveats:

  1. This works only up to 366 days of duration.
  2. If you want seconds as well as hours and minutes, then the picture statement should be:   

      picture fdur

        low-high= '%jD%0H:%0M:%0S' (datatype=datetime);

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

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

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 9 replies
  • 2103 views
  • 6 likes
  • 5 in conversation