BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Steve1964
Obsidian | Level 7

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?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
mkeintz
PROC Star

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 hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

View solution in original post

5 REPLIES 5
ChrisNZ
Tourmaline | Level 20

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. 

PaigeMiller
Diamond | Level 26

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)

--
Paige Miller
Steve1964
Obsidian | Level 7
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?
mkeintz
PROC Star

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 hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1068 views
  • 1 like
  • 4 in conversation