Help using Base SAS procedures

Another Date Question...

Reply
Occasional Contributor
Posts: 11

Another Date Question...

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

Super User
Posts: 11,343

Re: Another Date Question...

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.

Super User
Posts: 19,877

Re: Another Date Question...

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.

New Contributor JPM
New Contributor
Posts: 3

Re: Another Date Question...

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;

Ask a Question
Discussion stats
  • 3 replies
  • 243 views
  • 0 likes
  • 4 in conversation