The TSMODEL Procedure

Getting Started: TSMODEL Procedure

This section outlines the use of the TSMODEL procedure and describes some of the analysis techniques that you can perform on timestamped transactional data.

Suppose that a bank wants to analyze the transactions that are associated with each of its customers over time. Further, suppose that the CAS table mycas.transactions contains four variables that are related to these transactions: Customer, Date, Withdrawals, and Deposits. The following examples illustrate possible ways to analyze these transactions by using the TSMODEL procedure.

The following statements accumulate the timestamped transactional data to form a daily time series based on the accumulated daily totals of each type of transaction (Withdrawals and Deposits). These statements assume that your CAS engine libref is named mycas, but you can substitute any appropriately defined CAS engine libref.

proc tsmodel data=mycas.transactions
              out=mycas.timeseries(replace=yes)
              outarray=mycas.arrays(replace=yes);
   by Customer;
   id Date interval=day accumulate=total;
   var withdrawals deposits;
   outarrays Balance;
   submit;
   Balance[1] = deposits[1] - withdrawals[1];
   do t = 2 to _LENGTH_;
      Balance[t] = Balance[t-1] + (deposits[t] - withdrawals[t]);
   end;
   endsubmit;
quit;

The OUT= option requests that the resulting time series data for each customer be stored in the table mycas.timeseries. The OUTARRAY= option requests that the resulting time series data along with a newly created variable, Balance, be stored in the table mycas.arrays. Both tables are created in the CAS session’s current caslib.

The INTERVAL=DAY option requests that the transactions be accumulated on a daily basis within each Customer according to the values of the ID variable Date. The ACCUMULATE=TOTAL option requests that the sum of the transactions be calculated. After the transactional data are accumulated into a time series format, the example code computes a daily balance for each customer. Many of the procedures provided with SAS software can be used to perform further processing on the resulting time series data. The tables that are produced by PROC TSMODEL can also be used as input to subsequent PROC TSMODEL steps.

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

Figure 1: Summary of Time Series Processing

The TSMODEL Procedure

Processing Summary
CAS tableTRANSACTIONS
Number of analysis variables2
Number of rows read600
Number of groups read3
Memory for group packages (KB)1
Time to load groups (seconds)0.0079259872
Minimum time ID05NOV2007
Maximum time ID22NOV2007
Minimum time periods18
Maximum time periods18
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 code3
Number of groups failing0
Elapsed time to process groups (seconds)0.0168471336
Number of output table rows produced54
Number of array table rows produced54


You might want to plot the generated Balance series for some particular customer. The following code produces a graph for the customer named 'Bill'; the graph is shown in Figure 2.

proc sgplot data=mycas.arrays(where=(customer='Bill'));
   series x=Date y=balance;
run;

Figure 2: Balance for Bill

Balance for Bill


Last updated: October 12, 2022