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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 414 views
  • 0 likes
  • 3 in conversation