BookmarkSubscribeRSS Feed
uabcms
Calcite | Level 5
I need to create an indicator variable for each hour a patient is in surgery.

Ex:
surgery start time /// surgery end time
patient1 // 6:54 /// 8:05
patient2 // 13:45 /// 17:45
patient3 // 7:05 /// 7:30


For the 1st patient I would need an indicator for the 6 o'clock hour, the 7 o'clock hour and the 8 o'clock hour.
For the 2nd patient I would need an indicator for the afternoon hours of 1, 2, 3, 4 and 5.
For the 3rd patient I would need an indicator for the 7 o'clock hour.
7 REPLIES 7
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Use a SAS DATA step, and code a DO I=0 TO 23; and use the HOUR function to test your start and end variable range, marking your HR00 through HR23 variable with a 1 or 0, if the a test matches within the start and end time ranges.

Scott Barry
SBBWorks, Inc.
uabcms
Calcite | Level 5
Will this work if the start hour =23 (meaning the surgery started at 11pm) and
the end hour is 1 (surgery ended in the 1am hour)? the range here covers hours 23, 00 and 01.
Kind of new to the Do loop processing.
Thanks for your help.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
If your time-range crosses midnight, you will then need to introduce the DHMS function as well.

Scott Barry
SBBWorks, Inc.
Cynthia_sas
SAS Super FREQ
Hi:
I was wondering whether the data has a DATE variable as well as a TIME. That would make things so much easier. To me, it seems the day that somebody was operated on would be as important as the time. Also, an idea of what the purpose of the flag for each hour value would be. If you were going to add them up to get the total "hours" in surgery, then checking duration with date/time values and rounding would serve that purpose with flags that might or might cross the 24 hour boundary.

Also, depending on the purpose of the flags, it might be simpler to track things a different way...for example (my hour flags go from 1 to 24..just assuming that 24 hour long surgeries are rare):
[pre]
ptnum start end hr1 hr2 hr3 hr4 hr5 hr6 hr7 hr8 hr9 hr10 ....... hr24 numhrs
patient1 6:54 8:05 6 7 8 . . . . . . . . 3
patient2 13:45 17:45 13 14 15 16 17 . . . . . . 5
patient3 7:05 7:30 7 . . . . . . . . . . 1
patient4 22:15 1:30 22 23 00 1 . . . . . . . 4
[/pre]

But if you built your data this way, then hr1 is always the hour the surgery started. It's hard to give solution advice with a better picture of the data (is there a DATE variable) and an understanding of the use or purpose of the indicator variable for the hours.

cynthia
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Presumption here without a date contribution is that the DHMS function will increment the "end" variable by 86400 seconds, assigning the DHMS argument1 to a value of 1, as in:

if end lt start then end = DHMS(1,0,0,end);

So, without a "date", the surgery duration must be within a presumed 24 hour period.

Scott Barry
SBBWorks, Inc.
david_offlode
Calcite | Level 5
This might let you handle surgeries that cross midnight, one way is to use conditional processing.
[pre]
data surgery;
input patient $ start:time. end:time.;
format start end time.;
datalines;
patient1 6:54 8:05
patient2 13:45 17:45
patient3 7:05 7:30
patient4 23:53 1:22
patient5 0:45 3:30
;
run;

data surgery;
set surgery;

array HR HR00-HR23;
do i=0 to 23;
if hour(end) lt hour(start) then do;
if i ge hour(start) or i le hour(end) then HR{i+1} = 1;
end;
else do;
if i ge hour(start) and i le hour(end) then HR{i+1} = 1;
end;
end;

drop i;
run;
uabcms
Calcite | Level 5
Had a sudden and long distraction from this request.
Thanks to all for your help and suggestions.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

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
  • 7 replies
  • 964 views
  • 0 likes
  • 4 in conversation