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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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