Running Batch Code

You can download code to run a SAS Visual Forecasting project in batch mode. The batch code runs all of the pipelines and exports the output of the champion pipeline to the caslib and table name that you specify. The dependent and time variables must be assigned before running the batch code. If the project is shared, only users with Read-Write access can run the batch code.

If the project includes Interactive Modeling, check the log for messages that might indicate whether models that were designated as champion have failed. If this happens, the time seriesan aggregation of transactional data into specified time intervals and sorted according to unique combinations of the default attributes (BY variables) is missing a champion model. You need to reassign champion models for these time series.

Downloading the Batch Code

Follow these steps to download the batch code.

  1. From the SAS Model Studio Project page, select a project to run in batch.
  2. Click the menu icon (menu icon) and select Batch API.

    The Batch API window is displayed with the code for the project inline.

    Note: You can also download batch API code from within a project by clicking the settings icon settings icon in the project title bar.
  3. Select the Download Type at the bottom of the window. The options are as follows:
    • SAS: Downloads code to run in a SAS programming environment.
    • Python: Downloads code to run in a Python programming environment.
    • REST: Downloads a text file with example REST calls that you can use in an application.
  4. Click Download and select the location to save the file.

Editing the Batch Code

You need to provide these values in the downloaded code.

Note: This process shows how to authenticate by including your user name and password as macro variables in the batch code. If you prefer other options for authentication, see Options for Authenticating from Batch Code.
host

host name of the SAS Model Studio server

username

unique user name or ID of the user running the batch code

password

password that belongs to username

outputCaslib

the name of an existing caslib where you want to store the OUTFOR table for the project.

outputTable

the name of the table for the project output.

The following shows where to provide this information for the batch file.

SAS

Look for the following lines of code at the end of the batch file. The host, username, and projectId should already be provided. Update the password, outputCaslib, and outputTable variables as shown:


%let host = test.example.com;
%let username = my_username;
%let password = my_password;
%let projectId = a0548b2f-a669-4a10-a4dd-052c671c0c00;

/* Set the following to export the output data */
%let outputCaslib = myCas;
%let outputTable = OutputForecasts;
Python

Set these parameters on the command line. For example, if download.py is the file name of the Python batch code, invoke the command:

$ python download.py –-host test.example.com –-username my_username 
-–password my_password –-outputCaslib myCas –-outputTab OutputForecasts

If you have overrides in the project, they might generate conflicts when they are submitted by the batch code. You can update the batch code to automatically resolve these conflicts by adding autoresolve="true" to the code.

SAS

Find the PROC HTTP procedure that includes the following IN option with firstTransaction and lastTransaction.

in="{""firstTransaction"":""@first"",""lastTransaction"":""@last""}"

Add the autoResolve setting, as follows:

in="{""firstTransaction"":""@first"",""lastTransaction"":""@last"",
""autoResolve"":true}"
Python

Find the resubmit_overrides function:

def resubmit_overrides(env):

Update the body statement with autoResolve assignment.

body = '{\"firstTransaction\":\"@first\",\"lastTransaction\":\"@last\",
\"autoResolve\":true}'

Options for Authenticating from Batch Code

Editing the Batch Code shows how to authenticate by providing your user credentials as macro variables in the batch code. Here are two other options for authenticating when running batch.

SAS Studio automatic token

When running the batch code via SAS Studio, a token is automatically created for the user. It can be used by modifying each PROC HTTP call to include this statement:

oauth_bearer=SAS_SERVICES;

If you choose this option, the first PROC HTTP call needs to be removed from the downloaded SAS code. (The first PROC HTTP call is used to get a token through the user name and password.) It should look similar to this:


proc http
  method="POST"
  url="https://&host./SASLogon/oauth/token"
  in="grant_type=password%nrstr(&)username=&username.%nrstr(&)password=&password."
  out=resp;
  headers
    "Authorization"="Basic c2FzLmVjOg=="
    "Accept"="application/json"
    "Content-Type"="application/x-www-form-urlencoded";
run;
Register an authentication client

Follow the steps in Authentication to SAS Viya: a couple of approaches to register a client. Then you need to modify the batch code to request a token using the client instead of user name and password.

See Also

Last updated: March 16, 2026