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!
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
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
Another way to put it. When you count down there is no negative zero. The sequence is 2,1,0,-1,-2.
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!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: