The SAS Output Delivery System and reporting techniques

sas times

Reply
Occasional Contributor
Posts: 17

sas times

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.
Super Contributor
Super Contributor
Posts: 3,174

Re: sas times

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.
Occasional Contributor
Posts: 17

Re: sas times

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.
Super Contributor
Super Contributor
Posts: 3,174

Re: sas times

If your time-range crosses midnight, you will then need to introduce the DHMS function as well.

Scott Barry
SBBWorks, Inc.
SAS Super FREQ
Posts: 8,745

Re: sas times

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
Super Contributor
Super Contributor
Posts: 3,174

Re: sas times

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.
New Contributor
Posts: 3

Re: sas times

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;
Occasional Contributor
Posts: 17

Re: sas times

Had a sudden and long distraction from this request.
Thanks to all for your help and suggestions.
Ask a Question
Discussion stats
  • 7 replies
  • 185 views
  • 0 likes
  • 4 in conversation