BookmarkSubscribeRSS Feed
phoenix31
Fluorite | Level 6

I am trying to take the difference between the current time and a scheduled time which are in HH:MM format (I used TOD5.2 to convert them) and see negative hours.

Please let me know if more information is needed.

Thank you.

 

4 REPLIES 4
novinosrin
Tourmaline | Level 20

Hi @phoenix31 

 

Do you mean this?


data w;
t1='13:00't;
t2='15:00't;
dif=intck('hour',t2,t1);
run;
phoenix31
Fluorite | Level 6

Thank you for the update. The code you provided works when both values are in numeric format.

data want;
t1='13:00't;
t2='15:00't;
dif=intck('hour',t2,t1);
run;

My fields are in hh:mm format and if converted to numeric then the years, months ,days  and seconds since 1960.

 

I am using the below code but when the hours are negative my values are not right.

 

data work.demo_1;
set work.demo_base;
format dif tod5.2;
dif='Time1'n - 'Time2'n;
run;

Tom
Super User Tom
Super User

Why would you store time values with years included?

Do you have DATETIME values instead?

Even so the difference between two datetime values is still going to be a number of seconds. But it could be many days worth of seconds.

 

Did you want extract just the time part from the datetime value and compare those?  If so use the TIMEPART() function to extract just the time since midnight from your time since 1960 values.

novinosrin
Tourmaline | Level 20

Or perhaps, are you looking for picture format?

 



proc format;
   picture hr (default=6)
 low -  -1      =   '99:99' (prefix='-' mult=100)
  1  - high     =  '99:99' ( mult=100);
  ;

data want;
t1='13:00't;
t2='15:00't;
dif=intck('hour',t2,t1);
format dif hr. t time5.;
run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 4 replies
  • 472 views
  • 0 likes
  • 3 in conversation