I have patients admitted to an intensive care unit., their start datetime (istart) and their discharge datetime (istop). I need to know if the patient's last day in the intensive care unit crossed midnight. Below are some samples datetimes. Any ideas?
istart | istop | Cross_Midnight |
01/01/2020 13:00:00 | 01/03/2020 1:00:00 | Y |
01/01/2020 13:00:00 | 01/03/2020 23:00:00 | N |
01/01/2020 1:00:00 | 01/01/2020 23:50:00 | N |
01/01/2020 1:00:00 | 01/02/2020 2:00 | Y |
Thanks!
Andrew
How does one determine "the patient's last day in the intensive care unit crossed midnight"? I am not clear on this. However:
Something like this?
cross_midnight = intck('dtday',istart,istop,'d')>0;
Shouldn't row 2 have cross_midnight=Y ??
By the way, it is really helpful if you provide your example data as SAS DATA step code, and not as a screen capture, so we can actually test our sample code on your actual data. Please do that from now on.
@DocMartin wrote:
I didn't explain it clearly. What I didn't put in my post was the length of stay: 1.500 for the first patient above, then 2.500, 0.951, and 1.042. What I wanted to do is to see if the fractional part of the length of stay crossed midnight. Did the 0.500 part of a day include midnight, .0.500, 0.951, 0.042.?
How can a fractional part include midnight? Do you mean the istop time compared to the difference (istop time minus the fractional part) includes midnight?
Here's the SAS code:
data icu; input istart datetime16. istop datetime16.;
cards;
01Jan20:13:00:00 03Jan20:01:00:00
01Jan20:13:00:00 03Jan20:23:00:00
01Jan20:01:00:00 01Jan20:23:50:00
01Jan20:01:00:00 02Jan20:02:00
;
data icu1; set icu;
format istart istop datetime16.;
iculos = (istop - istart)/86400;
put istart istop iculos;
run;
01JAN20:13:00:00 03JAN20:01:00:00 1.5
01JAN20:13:00:00 03JAN20:23:00:00 2.4166666667
01JAN20:01:00:00 01JAN20:23:05:00 0.9201388889
01JAN20:01:00:00 02JAN20:02:00:00 1.0416666667
But this doesn't work if the stay in the ICU is greater than 24 hours (or does it)? How would this work on your row 2?
if intck('dtday',istart,istop) > 0
or
if datepart(istop) > datepart(istart)
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.