This example uses the TIMEDATA procedure to accumulate time-stamped transactional data that has been recorded at no particular frequency into time series data at a specific frequency. After the time series is created, the various SAS/ETS procedures related to time series analysis, seasonal adjustment and decomposition, modeling, and forecasting can be used to further analyze the time series data.
Suppose that the input data set Work.Retail
contains variables Store
and Timestamp
and numerous other numeric transaction variables. The BY variable Store
contains values that break up the transactions into groups (BY groups). The time ID variable Timestamp
contains SAS date values recorded at no particular frequency. The other data set variables contain the numeric transaction
values to be analyzed. It is further assumed that the input data set is sorted by the variables Store
and Timestamp
. The following statements form monthly time series from the transactional data based on the median value (ACCUMULATE=MEDIAN)
of the transactions recorded with each time period. Also, the accumulated time series values for time periods with no transactions
are set to zero instead of to missing (SETMISS=0) and only transactions recorded between the first day of 1998 (START=’01JAN1998’D
) and last day of 2000 (END=’31JAN2000’D) are considered and, if needed, extended to include this range.
proc timedata data=retail out=mseries; by store; id timestamp interval=month accumulate=median setmiss=0 start='01jan1998'd end ='31dec2000'd; var item1-item8; run;
The monthly time series data are stored in the data Work.Mseries
. Each BY group associated with the BY variable Store
contains an observation for each of the 36 months associated with the years 1998, 1999, and 2000. Each observation contains
the values Store
, Timestamp
, and each of the analysis variables in the input data set.
After each set of transactions has been accumulated to form a corresponding time series, accumulated time series can be analyzed
using various time series analysis techniques. For example, exponentially weighted moving averages can be used to smooth each
series. The following statements use the EXPAND procedure to smooth the analysis variable named Storeitem
:
proc expand data=mseries out=smoothed from=month; by store; id date; convert storeitem=smooth / transform=(ewma 0.1); run;
The smoothed series are stored in the data set Work.Smoothed.
The variable Smooth
contains the smoothed series.
If the time ID variable Timestamp
contains SAS datetime values instead of SAS date values, the INTERVAL=, START=, and END= options must be changed accordingly
and the following statements could be used:
proc timedata data=retail out=tseries; by store; id timestamp interval=dtmonth accumulate=median setmiss=0 start='01jan1998:00:00:00'dt end ='31dec2000:00:00:00'dt; var _numeric_; run;
The monthly time series data are stored in the data Work.Tseries,
and the time ID values use a SAS datetime representation.