Working with Time Series Data |
Using Interval Functions for Calendar Calculations |
With a little thought, you can come up with a formula that involves INTNX and INTCK functions and different interval types to perform almost any calendar calculation.
For example, suppose you want to know the date of the third Wednesday in the month of October 1991. The answer can be computed as
intnx( 'week.4', '1oct91'd - 1, 3 )
which returns the SAS date value ’16OCT91’D.
Consider this more complex example: how many weekdays are there between 17 October 1991 and the second Friday in November 1991, inclusive? The following formula computes the number of weekdays between the date value contained in the variable DATE and the second Friday of the following month (including the ending dates of this period):
n = intck( 'weekday', date - 1, intnx( 'week.6', intnx( 'month', date, 1 ) - 1, 2 ) + 1 );
Setting DATE to ’17OCT91’D and applying this formula produces the answer, N=17.
Copyright © 2008 by SAS Institute Inc., Cary, NC, USA. All rights reserved.