The field of time series forecasting has traditionally been dominated by statistical and machine learning models, but recent advancements in deep learning, particularly the development of foundation models (FMs), are beginning to revolutionize this domain.
Foundation models, also known as large pre-trained models, are deep learning models trained on vast and diverse datasets, enabling them to acquire broad general knowledge and patterns across multiple domains. These models have shown remarkable success in fields like computer vision and natural language processing, where their ability to be fine-tuned for specific tasks with relatively small amounts of data has proven highly effective.
Inspired by these successes, the concept of Time Series Foundation Models (TSFMs) has emerged as a promising approach for time series analysis. TSFMs leverage the foundation model paradigm to create generalized models capable of understanding and forecasting time series data across various applications. Examples of TSFMs include Amazon Science's Chronos models.
Chronos is a language modeling framework adapted for time series forecasting. It employs a minimalist approach by tokenizing time series values into a fixed vocabulary (through scaling and quantization of real values) and training existing language model architectures on these tokens without any time-series-specific design or features. Despite its simplicity, Chronos has shown to be effective, having comparable and occasionally superior zero-shot performance on unseen datasets, relative to methods that were trained specifically on them. For more details on Chronos's methodology and performance, refer to the paper linked here.
This article explores the application of foundation models for time series forecasting and demonstrates how users can leverage SAS® Visual Analytics (VA) to train and compare these advanced models with traditional forecasting techniques, such as Moving Average, Seasonal Naive, and Exponential Smoothing (ESM).
To enable users to train and compare models directly within the VA dashboard, this solution combines Data-Driven Content and SAS® Jobs. Specifically:
The executed SAS® code updates the CAS table used in the dashboard, allowing users to visualize different forecasted values in a single time series plot and select the best model. This solution supports datasets with:
This means your original dataset can include additional variables, but only these three—date, BY, and dependent variable—will be utilized by the SAS® code and VA dashboard. However, the solution can be expanded in future versions to include multiple BY variables or independent variables.
This article is divided into two sections:
Note: The SAS® Job's code accesses the Chronos model by calling an API endpoint where it is deployed. If you want to learn how to achieve this within your SAS® Viya installation, check out the first of a two-part series of articles on incorporating pre-trained forecasting models into SAS® Visual Forecasting.
For clarity, this section utilizes a specific dataset, such as the PRICEDATA table from the SASHELP library, though you can easily adapt the steps to any dataset of your choice.
Before diving into the code, let's first examine the final outcome, i.e. the VA dashboard:
The dashboard comprises four different objects:
Behind the scenes, the CAS table is updated with the forecasted values after each model is trained. To ensure the time series plot and list objects reflect these updates, automatic refresh is enabled; otherwise, these objects won't refresh as the data changes with the job execution.
Note: Automatic refresh only works when viewing the report, as explained in the documentation.
As mentioned, the forecasted values are plotted alongside historical data in the time series plot. To achieve this without altering the table structure (such as adding a new column for the forecasted values of the selected model), the PRICEDATA table (or your chosen dataset) undergoes pre-processing. This pre-processing is handled by the code in the following two screenshots (from the preprocessing.sas file). The red boxes highlight all the macro variables you can modify to adapt the code to your dataset, which are:
The pre-processing is performed in the PROC CAS procedure. Here’s a step-by-step explanation of what the code does:
As an example, the following image illustrates the PRICEDATA table before and after pre-processing:
With the dataset now prepared, we can begin describing the SAS® Job.
The SAS® code is composed of several sections:
For a detailed explanation of the code and step-by-step instructions on building a node for the Chronos model in SAS® Visual Forecasting, refer to the second article in the two-part series mentioned in the introduction.
Let's examine the HTML form, beginning with the head section.
The JavaScript code embedded in the HTML (described below) leverages some functions from two modules defined in the GitHub project called sas-visualanalytics-thirdpartyvisualizations. For this reason, they have been uploaded to the Files service and included in the HTML form using the SAS® Job Execution Web Application with a SCRIPT tag (as explained in the documentation). In the final section of the article, the complete procedure to do that will be provided.
The body section defines:
Initially, all buttons are disabled and are only enabled once the data is received from the VA dashboard.
Next, let's examine the script section. The basic structure is shown in the screenshot below:
The script begins by defining global variables. Variables with an underscore prefix store parameters received from the VA dashboard, while the model parameter holds the name of the selected model when a form button is clicked.
The script then listens for the DOMContentLoaded event to ensure the DOM is fully loaded before executing the code. This is a best practice when working with JavaScript. When the event occurs, the onDataReceived callback function is triggered, which processes the data received from the VA dashboard. Specifically, it verifies if:
If both conditions are met, the model selection buttons are enabled.
When a model button is clicked, the trainModel function is called with the model name as an argument. This function initiates a job via the callJob function and displays the job’s execution status in the jobResults section.
The callJob function prepares a form data object with necessary parameters, including the selected model and other VA-specific parameters, sending it via an HTTP call. The job is called with the _action parameter set to json. This results in the job response being a list in JSON format of output files created by the job. From the list, the files’ content can be retrieved using the URIs specified in the HREF keys (for more details, see here). The response is then processed to display a success or error message in the jobResults section:
Prerequisites:
Deployment steps:
Download the zip file attached to the article. Additionally, the same files are available for download from this GitHub repository, under the folder named ModelComparison.
Open the SAS® Job Execution web application by navigating to http://<your.host.name>/SASJobExecution/.
Create two new JavaScript files in a folder of your choice by using the New File option and selecting the appropriate File type. The steps are shown in the screenshot below.
Name the files as follows and paste the corresponding content from the GitHub repository’s util folder:
Create a new job in your preferred folder and give it a name. Follow a similar procedure as in the previous step.
Right-click on the job, select Properties, then navigate to Parameters and add a new parameter with the following details:
Setting _action to FORM (case-insensitive) causes the SAS® Job Execution Web application to transfer execution to the HTML form, which then calls the SAS® code stored in the job (with _action=JSON).
Replace the path after the equal sign in each of the following lines with the paths to your own files:
In the Parameter section of the Data pane on the left-hand side, modify the following parameters:
Note: The parameters _by_variable and _variable_name_parameter do not need modification, as they are automatically set by the Drop-down list control and the List control objects, respectively.
'Variable name'n = UpCase(_target) OR
(IF _by_variable = '.'
RETURN StartsWith('Variable name'n, 'forecasted') AND 'Sales Region'n = '.'
ELSE StartsWith('Variable name'n, 'forecasted') AND 'Sales Region'n = _by_variable)
Substitute 'Sales Region'n with your BY variable both at the end of line 3 and 4.
'Variable name'n = UpCase(_target) OR
(IF _by_variable = '.'
RETURN StartsWith('Variable name'n, 'forecasted') AND
In('Variable name'n, _variable_name_parameter) AND
'Sales Region'n = '.' AND
'Order Date'n > _end_historical_data
ELSE StartsWith('Variable name'n, 'forecasted') AND
In('Variable name'n, _variable_name_parameter) AND
'Sales Region'n = _by_variable AND
'Order Date'n > _end_historical_data)
Also in this case, replace 'Sales Region'n with your BY variable at the beginning of lines 5 and 9, and 'Order Date'n with your date variable at the beginning of lines 6 and 10.
(_job_cas_table = _job_cas_table) AND (_by_variable = _by_variable) AND (_target = _target) AND (_date = _date) AND (_byvar = _byvar) AND (_date_interval = _date_interval)
The reason of this dummy advanced filter (that always returns true) is that VA parameters are only passed in the JSON message to the DDC if the parameters affect the data that is being passed to the DDC (as explained in this article). ('Sales Region'n) <> ('.')
Substitute 'Sales Region'n with your BY variable.
In conclusion, the integration of foundation models into the realm of time series forecasting marks a significant advancement in the field. As foundation models continue to evolve, their application in time series forecasting will likely expand, offering even more effective solutions in the future.
With the DDC object described in this article, you can easily train and compare Time Series Foundation Models (TSFMs) like Chronos with traditional forecasting techniques using a VA dashboard. This allows you to evaluate their performance on your specific datasets. The models shown here are just examples, and you can customize the solution to include your preferred models and additional variables. Feel free to use this article as a starting point to create your own tailored version! 😊
I would like to express my sincere gratitude to Arpit Jain and David Weik for the opportunity to work on this project and for our discussions and idea exchanges, which led to the final outcome.
I also want to thank Iman Vasheghani Farahani for his assistance with questions regarding the TSMODEL procedure, as well as Michael Carman and Renato Luppi for their guidance in incorporating JavaScript files into the HTML form.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.