Data for several time series can be coded with separate groups of records for each time series. Data files coded this way are transposed from the form required by SAS procedures. Time series data can also be coded with descriptive information about the series included with the data records.
The following example reads time series data for the USPRICE data set coded with separate groups of records for each series. The data records for each series consist of a series description record and one or more value records. The series description record gives the series name, starting month and year of the series, number of values in the series, and a series label. The value records contain the observations of the time series.
The data are first read into a temporary data set that contains one observation for each value of each series.
data temp; length _name_ $8 _label_ $40; keep _name_ _label_ date value; format date monyy.; input _name_ month year nval _label_ &; date = mdy( month, 1, year ); do i = 1 to nval; input value @; output; date = intnx( 'month', date, 1 ); end; datalines; cpi 8 90 12 Consumer Price Index 131.6 132.7 133.5 133.8 133.8 134.6 134.8 135.0 135.2 135.6 136.0 136.2 ppi 6 90 13 Producer Price Index 114.3 114.5 116.5 118.4 120.8 120.1 118.7 119.0 117.2 116.2 116.0 116.5 116.3 ;
The following statements sort the data set by date and series name, and the TRANSPOSE procedure is used to transpose the data into a standard form time series data set.
proc sort data=temp; by date _name_; run; proc transpose data=temp out=usprice(drop=_name_); by date; var value; run; proc contents data=usprice; run; proc print data=usprice; run;
The final data set is shown in Figure 3.23.
Figure 3.23: Listing of USPRICE Data Set
Retransposed Data Set |
Obs | date | ppi | cpi |
---|---|---|---|
1 | JUN90 | 114.3 | . |
2 | JUL90 | 114.5 | . |
3 | AUG90 | 116.5 | 131.6 |
4 | SEP90 | 118.4 | 132.7 |
5 | OCT90 | 120.8 | 133.5 |
6 | NOV90 | 120.1 | 133.8 |
7 | DEC90 | 118.7 | 133.8 |
8 | JAN91 | 119.0 | 134.6 |
9 | FEB91 | 117.2 | 134.8 |
10 | MAR91 | 116.2 | 135.0 |
11 | APR91 | 116.0 | 135.2 |
12 | MAY91 | 116.5 | 135.6 |
13 | JUN91 | 116.3 | 136.0 |
14 | JUL91 | . | 136.2 |