Working with Time Series Data |
Alignment of SAS Dates |
Any date within the time interval that corresponds to an observation of a periodic time series can serve as an ID value for the observation. For example, the USCPI data in a previous example might have been recorded with dates at the 15th of each month. The person recording the data might reason that since the CPI values are monthly averages, midpoints of the months might be the appropriate ID values.
However, as far as SAS/ETS procedures are concerned, what is important about monthly data is the month of each observation, not the exact date of the ID value. If you indicate that the data are monthly (with an INTERVAL=MONTH) option, SAS/ETS procedures ignore the day of the month in processing the ID variable. The MONYY format also ignores the day of the month.
Thus, you could read in the monthly USCPI data with mid-month DATE values by using the following statements:
data uscpi; input date : date9. cpi; format date monyy7.; datalines; 15jun1990 129.9 15jul1990 130.4 ... more lines ...
The results of using this version of the USCPI data set for analysis with SAS/ETS procedures would be the same as with first-of-month values for DATE. Although you can use any date within the interval as an ID value for the interval, you might find working with time series in SAS less confusing if you always use date ID values normalized to the start of the interval.
For some applications it might be preferable to use end of period dates, such as 31Jan1994, 28Feb1994, 31Mar1994, ..., 31Dec1994. For other applications, such as plotting time series, it might be more convenient to use interval midpoint dates to identify the observations.
(Some SAS/ETS procedures provide an ALIGN= option to control the alignment of dates for output time series observations. In addition, the INTNX library function supports an optional argument to specify the alignment of the returned date value.)
To normalize date values to the start of intervals, use the INTNX function with a 0 increment. The INTNX function with an increment of 0 computes the date of the first day of the interval (or the first second of the interval for datetime values).
For example, INTNX(’MONTH’,’17OCT1991’D,0,’BEG’) returns the date ’1OCT1991’D.
The following statements show how the preceding example can be changed to normalize the mid-month DATE values to first-of-month and end-of-month values. For exposition, the first-of-month value is transformed back into a middle-of-month value.
data uscpi; input date : date9. cpi; format date monyy7.; monthbeg = intnx( 'month', date, 0, 'beg' ); midmonth = intnx( 'month', monthbeg, 0, 'mid' ); monthend = intnx( 'month', date, 0, 'end' ); datalines; 15jun1990 129.9 15jul1990 130.4 ... more lines ...
If you want to compute the date of a particular day within an interval, you can use calendar functions, or you can increment the starting date of the interval by a number of days. The following example shows three ways to compute the seventh day of the month:
data test; set uscpi; mon07_1 = mdy( month(date), 7, year(date) ); mon07_2 = intnx( 'month', date, 0, 'beg' ) + 6; mon07_3 = intnx( 'day', date, 6 ); run;
Copyright © SAS Institute, Inc. All Rights Reserved.