08-19-2014 12:27 PM
Hi! I have a data set of multiple temperature readings per provider from their refrigerators and their freezers that house vaccines. Because vaccines are easily ruined if they do not stay within required temp ranges, these providers are to monitor temps 24 hours a day using a special digital thermomter. I need to determine how much time each provider did NOT monitor temperatures. I will be using the LAG function to determine the difference between each line reading, however, the start/stop times of the recordings are provided in a Date/Time Start and Date/Time End format. Is there special formatting that needs to happen to these start/end columns of data before the LAG function will work correctly...or will SAS recognize these columns the way they are? I've researched this in every SAS book I have. I've got plenty of examples of how to change date formats...but haven't seen an example where date and time are in the same column. See a sample of my data set below.
Provider ID Storage Unit ID DataThermometer ID Date/Time Start Date/Time End Duration of Recording
0129 F LT13-7075 6/17/2014 10:34 6/24/2014 9:34 167:00:00
0129 F LT13-7075 6/24/2014 9:38 7/1/2014 8:53 167:15:00
0129 F LT13-7075 7/22/2014 14:35 7/15/2014 15:01 169:00:00
0155 R LT13-7084 7/1/2014 11:09 7/8/2014 16:24 173:15:00
0155 R LT13-7084 7/15/2014 9:41 7/22/2014 8:11 166:30:00
0155 R LT13-7084 7/22/2014 8:18 7/29/2014 9:18 169:00:00
0155 R LT13-7084 8/1/2014 16:19 8/11/2014 12:04 235:45:00
08-19-2014 12:52 PM
I would create datetime variables from the date and time by reading it with ANYDTDTE informat. Then the functions that work on date, time and datetime variables such as INTCK can be used.
08-19-2014 01:00 PM
This should be a datetime variable.
How are your dates stored? If the type is numeric and the format is datetime then you'll be fine.
You can do basic arithmetic to get durations and then apply time formats to get durations ie
format sample time9.;
Keep in mind that the datetime variable is storing data as number of seconds from January 1, 1960 compared to a date variable that is the number of days. Milliseconds are accomplished by using decimals (21.45) is 21 seconds.
11-11-2014 10:03 AM
/*The following mimics your data set and converts the text times to sas datetimes.
Lag is used in step two, along with the intck function to determine the number of minutes of unmonitored time.
Your report would be the sum of column Unmonitored_minutes.
The assumption is that your date/time fields would come into SAS as text, of course, and you would use your fieldname instead of the literal text string that I used to demonstrate how the informat anydtdtm can read a text string and convert it into a datetime value.
Change "dtminute" to "dthour" or "dtday" if you want your results by those units instead of minutes, etc.
Best of luck with your project. */
datetimestart=input("6/17/2014 10:34", anydtdtm19.);
format datetimestart datetime.;
datetimeend=input("6/24/2014 09:34", anydtdtm19.);
format datetimeend datetime.;
datetimestart=input("6/24/2014 09:38", anydtdtm19.);
datetimeend=input("7/1/2014 08:53", anydtdtm19.);
if first.obs then nextunit=StorageUnit;
else NextUnit = Lag(StorageUnit);
LastDateTimeEnd = Lag(datetimeend);
format lastdatetimeend datetime.;