BookmarkSubscribeRSS Feed
ebonyw
Calcite | Level 5


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:MM:SS format. I will need to manipulate the HH:MM:SS 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 StartDate/Time End(New Variable) Duration
10/31/13 10:2710/31/13 15:275:00:00
9/27/13 9:159/28/13 12:0026:45:00
9/28/13 12:159/28/13 13:151:00:00
10/1/13 8:0110/1/13 8:3600: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.

Datetime arguments:

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

3 REPLIES 3
PaigeMiller
Diamond | Level 26

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:MM:SS, you could use the proper format, which is the TIMEw.d format

--
Paige Miller
ebonyw
Calcite | Level 5

Thanks so much, Paige! I'm not sure if my values were true SAS datetime values. I will go look.

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 8758 views
  • 6 likes
  • 2 in conversation