BookmarkSubscribeRSS Feed
DocMartin
Quartz | Level 8

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?

 

istartistopCross_Midnight
01/01/2020 13:00:0001/03/2020  1:00:00Y
01/01/2020 13:00:0001/03/2020 23:00:00N
01/01/2020  1:00:0001/01/2020 23:50:00N
01/01/2020 1:00:0001/02/2020  2:00Y

 

Thanks!

Andrew

7 REPLIES 7
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
DocMartin
Quartz | Level 8
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.?
PaigeMiller
Diamond | Level 26

@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?

--
Paige Miller
DocMartin
Quartz | Level 8

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
DocMartin
Quartz | Level 8
Yikes, I figured it out for myself. I was making things too hard. All I had to do was:
if timepart(istart) > timepart(istop) then midnight = 'Y'; else midnight = 'N';
PaigeMiller
Diamond | Level 26

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?

--
Paige Miller

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1491 views
  • 0 likes
  • 3 in conversation