## Calculating missing time

Occasional Contributor
Posts: 11

# Calculating missing time

I have data from medical providers that documents the time they recorded temperatures in their vaccine storage units. They are supposed to record temps 24 hrs a day to make sure their refrigerators and freezers maintain appropriate temps so vaccines are not compromised. I know things happen where they may forget to plug their digital thermometers back after reading recordings or maybe have power failures...so they have a little leeway so 24 hours or more of missing recording time not good.

What would be the syntax to determine how much time is missing between a provider's storage unit record times?

Date/Time StartDate/Time EndMissing Time (New Variable)
9/27/13 9:159/28/13 12:00 ------
9/28/13 12:159/28/13 13:15Time from the end of their recording time to when they started recording again...14 minutes the provider didn't record
9/29/13 15:159/30/13 11:3026 hours the provider did not record temperatures
Super User
Posts: 23,776

## Re: Calculating missing time

Are the first two columns what your data looks like or does your colour coding indicate something about the data?

Occasional Contributor
Posts: 11

## Re: Calculating missing time

Sorry, Reeza. I was just trying to make it clear what was being used to calculate the missing time. The coloring truly doesn't mean anything. Sorry for the confusion. :-)

Super User
Posts: 23,776

## Re: Calculating missing time

The duration for the second record is 1 hour. Where does 14 minutes come from?

Occasional Contributor
Posts: 11

## Re: Calculating missing time

Reeza - The 14 minutes is the difference in time from the 1st line's ending and the 2nd line's start time. This doctor unplugged his thermometer/ended recording at 12:00 on 9/28/13 (END time for the first line). He started recording again at 12:15 on 9/28/13 (second line's START time). There was 14 minutes that he did have temperature data because his thermometer was not recording. Hope that makes sense. Thanks so much for your thoughts. I feel like pulling my hair out. Ahhh!

Posts: 3,061

## Re: Calculating missing time

Ok, I get it, so you want to subtract the end time on line 1 from the start time on line 2.

Same method works as in the other thread, once you have taken care of the issue that the data isn't on the same line.

Try something like this (assuming these are actual datetime values)

data abc;

set have;

prev_end_time=lag(end_time);

missing_time=start_time - prev_end_time;

format missing_time time.;

run;

--
Paige Miller
Occasional Contributor
Posts: 11

## Re: Calculating missing time

THANK YOU SOOOOO much, Paige. Yes...you understood my lengthy explanation correctly. :-) I'm going to try this now. Thank you!!!!!

Super User
Posts: 23,776

## Re: Calculating missing time

Use the lag function, see the code below. Then use if/then calculations based on that variable.

Please note that the duration from 00 to 15 is 15 minutes, if you need 14 minutes as you've indicated you'll need to use a correction factor.

If your variables are SAS Datetime variables, time_unplugged, will be noted in seconds and you'll need to convert that to minutes/hours as required or use the hhmm format applied. Otherwise, as indicated in your other questions you'll need to convert it to a SAS datetime.

data have;

informat time_start time_end datetime20.;

format time_: datetime21.;

input time_start time_end;

cards;

27SEP13:09:15:00 28SEP13:12:00:00

28SEP13:12:15:00 28SEP13:13:15:00

29SEP13:15:15:00 30SEP13:11:30:00

;

run;

data want;

set have;

time_unplugged=time_start-lag(time_end);

format time_unplugged hhmm7.;

run;

proc print data=want;

run;

Occasional Contributor
Posts: 11

## Re: Calculating missing time

Thank you so much, Reeza!!!!

Posts: 3,061

## Re: Calculating missing time

How could anyone or anything determine "missing time" from the information provided?

--
Paige Miller
Occasional Contributor
Posts: 11