Because INTCK counts the number of interval boundaries that are crossed, not a calculation of number of months which actually doesn't have a unique definition. Would a month be like February, 28 or 29 days or like December with 31 days? A 'month' doesn't have a standard definition so it's not a great unit of measure.
From the doc:
Returns the number of interval boundaries of a given kind that lie between two dates, times, or datetime values.
So your first record starts in Month = 8 and ends in Month = 10 which is two boundaries crossed, 9 and 10.
In your second record, Month =3and ends in Month = 4 which is a single boundary crossed.
Some references for further details:
https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p1md4mx2crzfaqn14va8kt7qvfhr.htm
https://blogs.sas.com/content/iml/2017/05/15/intck-intnx-intervals-sas.html
Here's a great, but longer and in depth, reference for dates and times in SAS https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354
@tSAS1 wrote:
I have the code below:
data want;
input mydate1 :yymmdd10. mydate2 :yymmdd10.;
format mydate1 mydate2 yymmddd10.;
datalines;
2020-08-27 2020-10-22
2020-03-01 2020-04-26
;
run;
data want2;
set want;
diff_months=intck("month",mydate1,mydate2);
diff_days=intck("day",mydate1,mydate2);
run;
proc print;run;
which provides the dataset want2
but I don't know why I don't have same diff_months=1 for both rows, since we have the same diff_days !
... View more