data test; result1=intck("month", "14Nov2021"d, "24jan2022"d); result3=intck("month", "7sep2021"d, "01dec2021"d);
result3=intck("month", "20sep2021"d, "01dec2021"d); run; proc print data=test; run;
how is the no of month calculated, is it round up or round down and where is the dividing line?
No rounding is done with the default behaviour of the INTCK function which is to count month boundaries. In your first example 14Nov2021 to 24Jan2022, this crosses two month boundaries (1 Dec 2021 and 1 Jan 2022) so RESULT1 = 2.
EDIT: If you add the continuous option then the results change. Try this:
data _null_;
result1=intck("month", "14Nov2021"d, "14Jan2022"d, 'C');
result2=intck("month", "14Nov2021"d, "13Jan2022"d, 'C');
result3=intck("month", "14Nov2021"d, "15Jan2022"d, 'C');
put _all_;
run;
SAS now counts complete months from the starting date. RESULT1 = 2 as 14 Nov to 14 Jan is 2 complete month intervals exactly. RESULT2 = 1 as only 1 month interval is complete. RESULT3 = 2 as it contains 2 complete month intervals - the extra day is not included.
From the documentation of the INTCK Function:
Returns the number of interval boundaries of a given kind that lie between two dates, times, or datetime values.
With an interval of MONTH, the boundary is midnight between the last day of a month and the first day of the following month.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.