I run the following code
NOTE: Invalid argument to function INTCK('month.3',18992,18993) at 行 76 列 3.data test; x=intck('day','31dec2011'd,'01jan2012'd); y=intck('week.2','31dec2011'd,'01jan2012'd); z=intck('month.3','31dec2011'd,'01jan2012'd); w=intck('year.2','31dec2011'd,'01jan2012'd); run; proc print ; run;
The note in window reads:
NOTE: Invalid argument to function INTCK('month.3',18992,18993) at line 76 column 3.
and variable z taken missing value。 why?
You want to know how many month boundaries are crossed between date1 and date2. The usual month boundary is crossed when you move from the last day of a calendar month to the 1st day of the next month.
Instead, you want the boundary crossed only when you move from the 1st day of a calendar month to the 2nd day of the same month. In that case you could count boundaries crossed via:
nmonths=intck('month',date1-1,date2-1);
Just subtract 1 day less than the month starting day from both dates. Then the number of calendar months crossed (produced by INTCK) will equal the number of user-specified months.
This will work for months declared to begin on the 1st through 28th. But your concept is not adequately defined for months beginning on the 29th through 31th, since some calendar months will not have such dates.
And that's pretty much the reason that SAS doesn't provide offsets like month.2, month.3, etc - because months do not have a constant number of subunits, whether they are said to be weeks or days. Years however (and semiyears and quarters) always have a constant number of subunits (months). The same goes for weeks (always 7 days).
The question, rather, is:
What did you expect month.3 to mean?
Have you read the documentation?
You cannot have a shift on month in you count single-month intervals.
According to the documentation at https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.3&docsetId=lefunctionsref&docsetTarg...
You can use any of these:
MONTH3.2
MONTH3
but not
MONTH.3
(which as @ChrisNZ points out, does not have meaning, it would be selecting the 3rd subdivision of a one month time period which is meaningless)
You want to know how many month boundaries are crossed between date1 and date2. The usual month boundary is crossed when you move from the last day of a calendar month to the 1st day of the next month.
Instead, you want the boundary crossed only when you move from the 1st day of a calendar month to the 2nd day of the same month. In that case you could count boundaries crossed via:
nmonths=intck('month',date1-1,date2-1);
Just subtract 1 day less than the month starting day from both dates. Then the number of calendar months crossed (produced by INTCK) will equal the number of user-specified months.
This will work for months declared to begin on the 1st through 28th. But your concept is not adequately defined for months beginning on the 29th through 31th, since some calendar months will not have such dates.
And that's pretty much the reason that SAS doesn't provide offsets like month.2, month.3, etc - because months do not have a constant number of subunits, whether they are said to be weeks or days. Years however (and semiyears and quarters) always have a constant number of subunits (months). The same goes for weeks (always 7 days).
@Steve1964 wrote:
How to set a one-month interval with the second day in the month as starting boundary, Since the interval name month.2 is meaningless?
It always helps to tell us what you are trying to do. Your original post didn't say this, so we weren't able to help. @mkeintz has given a good solution.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.