BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
kaushik_patra
Obsidian | Level 7

I am using the following syntax to calculate the minutes between two time variable.

INFTIME = INTCK('MINUTE',INPUT(EXSTTM,TIME8.),INPUT(EXENTM,TIME8.));

 

EXSTTM = 23:48

EXENTM = 00:48

The result is coming out as -1380 but I expect the result to be 60 min obviously. Guess the problem is the end time 00:48 which is the next day. Any suggestion?

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16
data have ;
EXSTTM = '23:48't;
EXENTM = '00:48't;
if EXENTM lt EXSTTM then duration=('24:00't-EXSTTM)+EXENTM; 
else duration=intck('minute',EXSTTM,EXENTM);
format EXSTTM EXENTM duration time5.;
run;
Thanks,
Jag

View solution in original post

4 REPLIES 4
Jagadishkatam
Amethyst | Level 16
data have ;
EXSTTM = '23:48't;
EXENTM = '00:48't;
if EXENTM lt EXSTTM then duration=('24:00't-EXSTTM)+EXENTM; 
else duration=intck('minute',EXSTTM,EXENTM);
format EXSTTM EXENTM duration time5.;
run;
Thanks,
Jag
kaushik_patra
Obsidian | Level 7

Thanks Jag. It worked; I had to do a minor tweak to divide it by 60 as the duration is calculated in seconds and I wanted it to be in minutes.

Kaushik

ballardw
Super User

If you are going to compare times across midnight you will need to incorporate a DATE portion, make a datetime value and then you can use intnx function to return minutes between directly using the 'minute' interval.

kaunth
Calcite | Level 5

what if EXSTTM=03:38

and EXENTM=03:18 which is on the same day then this code will create problems.

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!

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
  • 9773 views
  • 3 likes
  • 4 in conversation