Don't apply the format when creating the value, that changes the values that INTCK expects to see.
When you formatted the value you changed a numeric value on the order of 23181 to 20230620. INTCK and other date functions in SAS expect to see a value that is the number of days since 01JAN1960 as an argument. So the formatted value such as 20230620 would be roughly in year 55,388. The SAS date functions won't work with any dates past the year 20,000 .
If you have a need for a formatted version of Begin and End then create separate non-formatted variables.
A SAS date value is an integer count of days, starting at 1960-01-01.
So the number 20211231 would be very far in the future, beyond the range of available formats.
Maxim 28: Macro Variables Need no Formats.
%let End = %sysfunc(intnx(month,%sysfunc(today()),-4,e));
%let Begin = %sysfunc(intnx(year,%sysfunc(today()),-2,e));
DO NOT format macro variables. This prevents mathematical operations from working correctly.
Use unformatted macro variables
%let End = %sysfunc(intnx(month,%sysfunc(today()),-4,e));
%let Begin = %sysfunc(intnx(year, %sysfunc(date()), -2, e));
%put &Begin;
%put &End;
%let count_months =%sysfunc(intck(month,&Begin.,&End.));
%put &count_months;
Don't apply the format when creating the value, that changes the values that INTCK expects to see.
When you formatted the value you changed a numeric value on the order of 23181 to 20230620. INTCK and other date functions in SAS expect to see a value that is the number of days since 01JAN1960 as an argument. So the formatted value such as 20230620 would be roughly in year 55,388. The SAS date functions won't work with any dates past the year 20,000 .
If you have a need for a formatted version of Begin and End then create separate non-formatted variables.
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.