Working with Time Series Data |
Incrementing Dates by Intervals |
Use the INTNX function to increment dates by intervals. For example, suppose you want to know the date of the start of the week that is six weeks from the week of 17 October 1991. The function INTNX(’WEEK’,’17OCT91’D,6) returns the SAS date value ’24NOV1991’D.
One practical use of the INTNX function is to generate periodic date values. For example, suppose the monthly U.S. Consumer Price Index data in a previous example were recorded without any time identifier on the data records. Given that you know the first observation is for June 1990, the following statements use the INTNX function to compute the ID variable DATE for each observation:
data uscpi; input cpi; date = intnx( 'month', '1jun1990'd, _n_-1 ); format date monyy7.; datalines; 129.9 130.4 ... more lines ...
The automatic variable _N_ counts the number of times the DATA step program has executed; in this case _N_ contains the observation number. Thus _N_–1 is the increment needed from the first observation date. Alternatively, you could increment from the month before the first observation, in which case the INTNX function in this example would be written INTNX(’MONTH’,’1MAY1990’D,_N_).
Copyright © SAS Institute, Inc. All Rights Reserved.