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
| Processing Summary | |
|---|---|
| CAS table | TRANSACTIONS |
| Number of analysis variables | 2 |
| Number of rows read | 600 |
| Number of groups read | 3 |
| Memory for group packages (KB) | 1 |
| Time to load groups (seconds) | 0.0079259872 |
| Minimum time ID | 05NOV2007 |
| Maximum time ID | 22NOV2007 |
| Minimum time periods | 18 |
| Maximum time periods | 18 |
| Number of nodes run | 1 |
| Number of nodes with data | 1 |
| Number of nodes with groups | 1 |
| Number of threads budgeted | 32 |
| Minimum thread group count | 0 |
| Maximum thread group count | 1 |
| Minimum threads active | 32 |
| Maximum threads active | 32 |
| Number of groups processed by submitted code | 3 |
| Number of groups failing | 0 |
| Elapsed time to process groups (seconds) | 0.0168471336 |
| Number of output table rows produced | 54 |
| Number of array table rows produced | 54 |
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
