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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.