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?
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;
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. 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
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.
what if EXSTTM=03:38
and EXENTM=03:18 which is on the same day then this code will create problems.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.