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
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.
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
sample=date_end-date_start;
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.
Hi.
/*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. */
data testtime;
obs=1;
StorageUnit="F";
ThermoID="LT13-7075";
datetimestart=input("6/17/2014 10:34", anydtdtm19.);
format datetimestart datetime.;
datetimeend=input("6/24/2014 09:34", anydtdtm19.);
format datetimeend datetime.;
output;
obs=2;
StorageUnit="F";
ThermoID="LT13-7075";
datetimestart=input("6/24/2014 09:38", anydtdtm19.);
datetimeend=input("7/1/2014 08:53", anydtdtm19.);
output;
run;
data work.unmonitored;
set work.testtime;
by obs;
LastDateTimeend=datetimeend;
if first.obs then nextunit=StorageUnit;
else NextUnit = Lag(StorageUnit);
LastDateTimeEnd = Lag(datetimeend);
format lastdatetimeend datetime.;
Unmonitored_minutes=intck("dtminute",lastdatetimeend,datetimestart);
output;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.