Why is SAS doing this? It is obviously wrong:
t = intck('min', date1, date2);
date1 is 18feb2023 12:59
date2 is 18feb 2023 13:20
The interval should be 21 minutes, but I am getting -699 minutes.
I understand it is confused by the military time, but what is the explanation and how to work around this?
Any thoughts are welcome!
Check the actual values of DATE1 and DATE2. The values you showed are 21 minutes apart.
data test;
date1 ='18feb2023 12:59'dt;
date2 ='18feb2023 13:20'dt;
diff1 = intck('min',date1,date2);
diff2 = intck('min',date1,date2,'c');
diff3 = (date2-date1)/60;
format date1 date2 datetime19.;
run;
proc print;
run;
Obs date1 date2 diff1 diff2 diff3 1 18FEB2023:12:59:00 18FEB2023:13:20:00 21 21 21
To get -699 minutes you would have had to mistakenly coded the second date as 1:20 AM instead of 1:20 PM.
data test;
date1 ='18feb2023 12:59'dt;
date2 ='18feb2023 13:20'dt;
date3 = date1 - 699*60;
diff1 = intck('min',date1,date2);
diff2 = intck('min',date1,date2,'c');
diff3 = (date2-date1)/60;
format date1-date3 datetime19.;
run;
Check the actual values of DATE1 and DATE2. The values you showed are 21 minutes apart.
data test;
date1 ='18feb2023 12:59'dt;
date2 ='18feb2023 13:20'dt;
diff1 = intck('min',date1,date2);
diff2 = intck('min',date1,date2,'c');
diff3 = (date2-date1)/60;
format date1 date2 datetime19.;
run;
proc print;
run;
Obs date1 date2 diff1 diff2 diff3 1 18FEB2023:12:59:00 18FEB2023:13:20:00 21 21 21
To get -699 minutes you would have had to mistakenly coded the second date as 1:20 AM instead of 1:20 PM.
data test;
date1 ='18feb2023 12:59'dt;
date2 ='18feb2023 13:20'dt;
date3 = date1 - 699*60;
diff1 = intck('min',date1,date2);
diff2 = intck('min',date1,date2,'c');
diff3 = (date2-date1)/60;
format date1-date3 datetime19.;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.