BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Chaupak
Obsidian | Level 7

Hi, I met a problem when calculating the difference of months between two dates. Here are the sample codes:

 

data test;
	dt1 = "25Aug2011"d;
	dt2 = "23Feb2012"d;
	dt1_dt2 = intck("month",dt1,dt2,"c");
	dt2_dt1 = intck("month",dt2,dt1,"c");
	format dt1 dt2: yymmdd10.;
run;

Here I calculated the month difference between date1 2011-08-25 and date2 2012-02-23. When I put date1 before date2 (dt1_dt2) in the INTCK function, it returns 5, because the time interval is slightly <6 months. However, when I put date2 before date1 (dt2_dt1), it returns -6. Shouldn't it be -5, since I just changed the order of two dates? Anyone can help me with it?

 

Thanks!

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

One month from 23FEB2012 is any date 23MAR2012 to 22APR 2012

Zero months from 23FEB2012 is any date 23FEB2012 to 22MAR2012.

Negative one months is any date 23JAN2012 to 22FEB2012 (so 23FEB2012 to 22FEB2012 on this scale is -1 months)

and so on

--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

One month from 23FEB2012 is any date 23MAR2012 to 22APR 2012

Zero months from 23FEB2012 is any date 23FEB2012 to 22MAR2012.

Negative one months is any date 23JAN2012 to 22FEB2012 (so 23FEB2012 to 22FEB2012 on this scale is -1 months)

and so on

--
Paige Miller
Tom
Super User Tom
Super User

Another way to put it.  When you count down there is no negative zero.  The sequence is 2,1,0,-1,-2.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 3 replies
  • 926 views
  • 0 likes
  • 3 in conversation