BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
pink_poodle
Barite | Level 11

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

Tom_0-1702957269142.png

 

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

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;

Tom_0-1702957269142.png

 

pink_poodle
Barite | Level 11
Yes, this is exactly what happened, thank you!

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Early bird rate extended! Save $200 when you sign up by March 31.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 876 views
  • 1 like
  • 2 in conversation