SAS Cloud Time Series Processing
Cloud-Based Time Series Processing with SAS Visual Forecasting and External Languages
Overview of the TSMODEL Infrastructure
The TSMODEL infrastructure is a cloud-based time series processing system designed to scale to millions of time series, provided the underlying infrastructure allows. It works with Cloud Analytic Services (CAS) to run time series analysis on a distributed cluster. The system handles data movement and data processing automatically, enabling parallel execution across worker nodes.
Key Capabilities
Handles large-scale data sets with millions of time series
Scales efficiently with added cores — tests have shown linear scaling up to 400 threads on an 87 GB dataset, completing in about 5 minutes (compared to 130 hours using serial processing)
Supports multiple interaction modes: SAS Visual Forecasting GUI, SAS code (e.g., PROC TSMODEL), and other CAS-compatible clients
System Architecture and Execution Model
Cluster Setup
A typical deployment involves a cluster of worker nodes connected to a distributed file system. The distributed file system provides storage and management across hardware, but the user only interacts with data tables (time series data). The architecture is abstracted so that the user submits a script (SAS, Python, R, or a combination) that is replicated to all worker nodes automatically.
Script Compilation and Execution
The script is compiled into machine code on each worker node for efficiency.
For Python and R code, the system launches a separate interpreter process (e.g.,
python.exeon Windows) and feeds the extracted code as a file (e.g.,code.py).Data distribution from the distributed file system to worker nodes is load-balanced. For example, with 7 time series per table across 4 worker nodes, three nodes get 2 time series each, and one node gets 1 — allowing parallel processing across CPU cores.
Output data is automatically sent back to the distributed file system; the user only specifies output table names.
Shared variables between SAS and external languages are automatically transferred — the user specifies which variables to share, and the system handles the rest.
The External Languages Package
Introduced at the end of 2019, the External Languages Package allows users to run Python and R code within the SAS Visual Forecasting environment. It is part of the larger set of packages that come with Visual Forecasting, enabling integration with all existing forecasting features.
Key Features
No restrictions on code: Any Python or R code can be used (even "hello world").
Version flexibility: Supports relatively recent versions (Python 2.6+, R 2.5+).
No required third-party packages: Only libraries needed for user processing must be installed.
Automatic data transfer: Variables specified by the user are shared between SAS and the external language process.
Access control: Flexible methodology to restrict file system and process access for security.
Object-Oriented Design
The package uses an object-oriented approach with three main categories of objects:
Interpreter Objects
Used to directly interact with the external language. They provide methods to:
Insert code in three ways:
Directly in the SAS script (as a string)
Load from a file accessible to all worker nodes
Load from a CAS table
Specify shared variables that will be available in the Python or R process
Specify environment variables if the code relies on them
Run the code
Retrieve miscellaneous information (exit codes, run times, etc.)
Collector Objects
Used to store data into CAS tables after execution:
Logs: Anything written to standard output/error (e.g., print statements) can be stored for later review — especially useful for debugging when processing millions of time series.
Shared variable status: Records whether shared variables were successfully written back.
Source code: Can be stored for reuse.
Repeater Objects
Used to load stored source code from CAS tables back into the system.
Working Example: Moving Average Calculation with Python
A complete, working SAS program demonstrates how to calculate a moving average of a time series using Python, running in parallel across distributed time series.
Setup in PROC TSMODEL
proc tsmodel data=mycas.skinproduct
outarray=mycas.outarray
outscalar=mycas.outscalar
outlog=mycas.pylog
date=date interval=week
by=distribution_center
var revenue(acc=sum)
runtime=run_time
outarray=m_average;Explanation of key statements:
input data:
mycas.skinproduct— synthetic dataset of fictional skincare product sales, weekly time interval, with multiple distribution centers.output data:
outarray(for array output like moving averages),outscalar(for scalars like runtime),pylog(for Python logs).BY variable:
distribution_center— each unique value defines a separate time series that will be processed in parallel on different worker nodes.VAR statement:
revenueis the variable to be analyzed, accumulated by sum over each time bucket.runtime: scalar output capturing pipeline processing time.
outarray:
m_average— the moving average to be computed.
Using External Language Objects
The program first requires the External Languages Package:
require extlang;Inside the SUBMIT block (the code that runs on the cluster):
submit;
/* Create and initialize interpreter */
declare object py(python2);
rc = py.initialize();
/* Specify shared variables */
rc = py.addVariable("revenue", "alias", "y");
rc = py.addVariable("m_average", "readOnly", "false");
/* Add Python code (string-based) */
rc = py.addCode(...
... Python code to compute moving average using convolution ...
);
/* Run the Python code */
rc = py.run();
/* Get runtime */
run_time = py.getRunTime();
/* Collect logs */
declare object outLog(outextlog);
rc = outLog.collect(py, "logCollect= _all_");
endsubmit;Key points about shared variables:
addVariablehas a required variable name (e.g.,revenue) and optional parameters:alias: Allows the variable to be referenced by a different name in the external code (e.g.,
yinstead ofrevenue), avoiding code changes.readOnly: Default is
true(sends data only one way). For output variables likem_average, setreadOnly="false"to write results back to SAS.
Log collection uses an outextlog object and the collect method with the Python object and an argument specifying _all_ logs.
After the pipeline runs, output tables can be retrieved and plotted using SAS procedures like SGPLOT or PRINT.
Integration with Model Studio (GUI)
The External Languages Package can also be used through the SAS Visual Forecasting GUI (Model Studio). An open source node can be added to a pipeline to include Python or R models as part of the automatic model selection process. For example, an R ARIMA model was shown to be automatically selected and used in some pipeline scenarios.
Summary
The combination of TSMODEL's cloud-based infrastructure and the External Languages Package provides a powerful, scalable environment for time series analysis that extends beyond SAS to leverage Python and R. The system abstracts data distribution, parallel execution, and variable sharing, allowing users to integrate custom code seamlessly while benefiting from Visual Forecasting's full feature set.

Ask anything
We've read this whole study set, so questions about it get the best answers.