02-24-2015 10:58 AM
Hi! I am EXTREMELY wet behind the ears in SAS. I have data of medical providers and how long they recorded temperatures in their vaccine storage units. The amount of time that these providers were recording temperatures in their refrigerators and freezers is presented in a DATE/HH:MM format. I need to create a new variable (duration), that subtracts the End time from the Start time to determine the total time they were recording. The data in my new duration variable should be presented in HH:MMS format. I will need to manipulate the HH:MMS data in the duration column in different ways by provider, so I need SAS to continue to recognize it in this format and add them correctly.
|Date/Time Start||Date/Time End||(New Variable) Duration|
|10/31/13 10:27||10/31/13 15:27||5:00:00|
|9/27/13 9:15||9/28/13 12:00||26:45:00|
|9/28/13 12:15||9/28/13 13:15||1:00:00|
|10/1/13 8:01||10/1/13 8:36||00:30:00|
|Need to be able to add Duration correctly - 33:15:00|
I found the following INTCK statements that seem as though they may be on the right track of giving me what I need, however, the statements split out the hours/minutes/seconds. It doesn't give me the duration in the hh:mm:ss format.
hours=intck ('hour' , '01jan2009:00:00:00'dt, '01jan2010:00:00:00'dt);
minutes=intck ('minute' , '01jan2009:00:00:00'dt, '01jan2010:00:00:00'dt);
seconds=intck ('second', '01jan2009:00:00:00'dt, '01jan2010:00:00:00'dt);
The result values will be:
*hours = 8760
*minutes = 525600
*seconds = 31536000
02-24-2015 11:07 AM
If the values are true SAS datetime values, then the duration is simply the subtraction of the End minus Start times. This is the duration in seconds. INTCK is not needed.
If you want to present this number of seconds as HH:MMS, you could use the proper format, which is the TIMEw.d format
02-24-2015 01:06 PM
If they are not datetime values (for example they are characters), then you should convert them to datetime, that would be the easiest path forward.