TSMODEL Procedure

Example 29.1 Accumulating Transactional Data into Time Series Data

This example uses the TSMODEL procedure to accumulate timestamped transactional data that have been recorded at no particular frequency into time series data at a specific frequency.

Suppose that the input table mylib.retail contains variables Store and Timestamp and numerous other numeric transaction variables. The BY variable Store contains values that divide the transactions into groups (BY groups). The time ID variable Timestamp contains SAS date values that are recorded at no particular frequency. The other variables, Item1–Item8, contain the numeric transaction values to be analyzed. The following statements form monthly time series from the transactional data.

These statements assume that your libref is named mylib, but you can substitute any appropriately defined libref.

proc tsmodel data=mylib.retail
     out=mylib.mseries(replace=yes);
   by store;
   id timestamp interval=month
                accumulate=avg
                setmiss=0
                start='01jan1998'd
                end  ='31dec2000'd;
   var item1-item8;
run;

The ACCUMULATE=AVG option in the ID statement accumulates the transactions that are recorded with each time period based on the average values. The SETMISS=0 option in the ID statement sets the accumulated time series values for time periods that have no transactions to 0 instead of to missing. The START='01JAN1998'D and END='31DEC2000'D options request that only transactions recorded between the first day of 1998 and the last day of 2000 be considered and, if needed, extended to include this range.

The monthly time series data are stored in the table mylib.mseries. Each BY group that is associated with the BY variable Store contains an observation for each of the 36 months that are associated with the years 1998, 1999, and 2000. Each observation contains the values Store, Timestamp, and each of the analysis variables Item1–Item8 in the input table.

The TSMODEL procedure prints a summary of the time series processing that is performed, as shown in Output 29.1.1.

Output 29.1.1: Summary of Accumulation Processing

The TSMODEL Procedure

Processing Summary
CAS tableRETAIL
Number of analysis variables8
Number of rows read400
Number of groups read4
Memory for group packages (KB)1
Time to load groups (seconds)0.0077979565
Minimum time IDNOV1998
Maximum time IDDEC2000
Minimum time periods36
Maximum time periods36
Number of nodes run1
Number of nodes with data1
Number of nodes with groups1
Number of threads budgeted32
Minimum thread group count0
Maximum thread group count1
Minimum threads active32
Maximum threads active32
Number of groups processed by submitted code4
Number of groups failing0
Elapsed time to process groups (seconds)0.0124080181
Number of output table rows produced144


After each set of transactions has been accumulated to form a corresponding time series, the 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.

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 tsmodel data=mylib.retail
   out=mylib.tseries(replace=yes);
   by store;
   id timestamp interval=dtmonth
                accumulate=avg
                setmiss=0
                start='01jan1998:00:00:00'dt
                end  ='31dec2000:00:00:00'dt;
   var item1-item8;
run;

The monthly time series data are stored in the table mylib.tseries, and the time ID values use a SAS datetime representation.

Last updated: July 09, 2026