INTNX Funtion In SAS
The SAS INTNX function is very useful however you should be careful when using the time increments.
If you use
next_month=intnx('month',today,1);
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
next_month=intnx('month',today,0);
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
next_month=intnx('month',today,1)-1;
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
next_week=intnx('Day',week,+7);
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