29 May 2009

How to use INTNX Funtion In SAS - Quick Guide with Examples

INTNX Funtion In SAS

The SAS INTNX function is very useful however you should be careful when using the time increments.

If you use


it gets you the next calendar month, not one month from today. For example, today’s date is July 29, 2005 and the next_month will be defined above as August 1, 2005. So it follows the calendar month to go to the next month or the previous month. IF you use a zero increment as


the result will be July 1, 2005 the first day of the current month. To get the last day of the month, you want to use the above function and subtract 1 from as in


which will give next_month as July 31, 2005.

Now more confusions arise only when you use the week function since businesses may have a custom week definition for their purposes. While companies typically follow the calendar month, their business week may be defined as Monday thru Sunday, or Saturday thru Friday etc. This often arises when you are using retail data from either Syndicated sources or from retailers directly such as Wal-Mart, Target. They all have their own customized week definitions.

Let us say your data is in the form of a weekending date for every week. Then you may want to use the INTNX function to grab specific weeks in your data using the Day increment as


If you use the ‘week’ increment it will capture the following Sunday which may be incorrect, if your week does not start on a Sunday. Even if it does, the weekending notation means you are coding your week variable with a Saturday not a Sunday.

Now if your business is on a 4-4-5 week month calendar, then this raises everything to a new complication.

Leave a Reply