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

Hello,

Lets say that there are 2 columns :X1

Each of them is sas date time column.

Lets say that the formatted values are:

X1=22AUG2022:09:35:00
X2=22AUG2022:09:26:06

LEts say that I want to calculate the difference in minutes between X1 and X2.

I am using intck as following: 
INTCK('minute',X1,X2) as dif_in_minutes

 

My question:

Why am I getting minus 9 and not plus 9???
I was sure that the difference that is calculated is X1-X2 by but the result I see that it is X2-X1

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

The second argument is the from value, and the third argument is the to value. If "to" is before "from", the function returns a negative value.

If you only want to get the difference, irrespective of the order, use the ABS function around the INTCK.

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

The answer is quite simple. As the INTCK Function Documentation says, it

 

Returns the number of interval boundaries of a given kind that lie between two dates, times, or datetime values.

 

Also:

 

INTCK returns a negative value whenever the first date(time) is later than the second date(time) and the two date(time)s are not in the same discrete interval.

 

 

Kurt_Bremser
Super User

The second argument is the from value, and the third argument is the to value. If "to" is before "from", the function returns a negative value.

If you only want to get the difference, irrespective of the order, use the ABS function around the INTCK.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 710 views
  • 2 likes
  • 3 in conversation