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-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
  • 2 replies
  • 415 views
  • 1 like
  • 2 in conversation