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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1954 views
  • 0 likes
  • 3 in conversation