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;
... View more