BookmarkSubscribeRSS Feed
kdp
Calcite | Level 5 kdp
Calcite | Level 5
I have data that is coming in with timestamps with more than 24 hours...e.g. 26:32:17.

When using the hour function on this timestamp, it returns 2 and not 26.

How can I make it recognize 26 rather than 2? I tried converting the time-stamp into a character value and then parsing out the hour. However, that didn't work either.

Thanks,
kdp
3 REPLIES 3
TomKari
Onyx | Level 15
I'm guessing a bit about how you're turning your timestamp into a datetime value, but I think your problem is the difference between a time and a duration. Inputting 26:32:17 is most likely creating a datetime of 2 AM, January 2 1960. So the HOUR function is correctly returning 2.

The INTCK function returns information about an interval. If you ask for the number of hours in the interval between 12 AM January 1 1960 (datetime value 0) and your timestamp, you should get the correct 26.

I've put together a small sample program to demonstrate the difference.

Program
----------

data timetest;
chartime = "26:32:17";
timeval = input(chartime, time8.);
file log;
As_datetime = put(timeval, datetime.); put As_datetime =;
As_hour = hour(timeval); put As_hour =;
As_interval = intck("HOUR",0,timeval); put As_interval =;
run;

Log
---

As_datetime=02JAN60:02:32:17
As_hour=2
As_interval=26
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Another option is to run the data-string as formatted value then use INPUT to convert back to number.

Scott Barry
SBBWorks, Inc.


27 data _null_;
28 hr = input(put('26:00:00't,hour.),best.);
29 put hr= ;
30 run;

hr=26
NOTE: DATA statement used ...
kdp
Calcite | Level 5 kdp
Calcite | Level 5
Thanks guys! I knew someone would have an answer.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 1350 views
  • 0 likes
  • 3 in conversation