BookmarkSubscribeRSS Feed

Managing Models using SAS Model Manager Macros and Proc HTTP

Started ‎04-07-2025 by
Modified ‎04-07-2025 by
Views 1,578

SAS Model Manager is a vital component of the SAS Viya platform, providing a structured environment for managing the entire lifecycle of analytical models—from development and validation to deployment and monitoring. To enhance and automate these processes, SAS Model Manager offers a collection of macros that facilitate various model management tasks. This article will list the available macros and also provide an example on how to test a model published to Micro Analytic Service (MAS).

 

Available SAS Model Manager Macros

Usage

 

SAS Model Manager macros are useful for users who are writing SAS code to manage their analytics lifecycle. They provide a set functionalities to ease the workflow using familiar code and from a single user interface: SAS Studio or SAS Extension for Visual Studio Code. The usage of macros provides reusability and also allows scheduling of the tasks.

 

Model Management Macros

%MM_GET_TOKEN Retrieves an authentication token for interacting with SAS services
%MM_CREATE_REPOSITORY Creates a new repository for organizing and storing models
%MM_CREATE_FOLDER Generates a folder within a repository to help categorize models
%MM_CREATE_PROJECT Initiates a new project for managing related models
%MM_CREATE_PROJECTVERSION Establishes a new version within a project for version control
%MM_IMPORT_MODEL Imports a model into SAS Model Manager for management and deployment
%MM_IMPORT_ASTORE_MODEL Imports an ASTORE model into SAS Model Manager
%MM_MODEL_ADD_JSONFILES Adds JSON files to a specified model
%MM_GET_REPOSITORY_ID Retrieves the unique identifier (UUID) of a specified repository
%MM_GET_FOLDER_ID Obtains the UUID of a specified folder
%MM_GET_PROJECT_ID Fetches the UUID of a specified project
%MM_GET_PROJECTVERSION_ID Acquires the UUID of a specified project version
%MM_GET_MODEL_ID Retrieves the UUID of a specified model
%MM_GET_FILEURI Obtains the URI of a specified file
%MM_DELETE_REPOSITORY Removes a specified repository
%MM_DELETE_FOLDER Deletes a specified folder
%MM_DELETE_PROJECT Eliminates a specified project
%MM_DELETE_PROJECTVERSION Removes a specified project version
%MM_DELETE_MODEL Deletes a specified model from the repository
%MM_PUBLISH_MODEL Publishes a model to a designated destination for scoring or production use

 

Performance Monitoring Macro

%MM_PERFORMANCE_MONITOR Defines and runs performance monitoring for a champion or challenger model

 

Publish Destination Macros

%MM_DEFINEPUBLISHDESTINATION Defines a new publishing destination
%MM_DELETEPUBLISHDESTINATION Deletes an existing publishing destination
%MM_UPDATEPUBLISHDESTINATION Updates the properties of an existing publishing destination
%MM_PRINTPUBLISHDESTINATION Lists all defined publishing destinations

 

Feature Contribution Index (FCI) Macros

%COMPUTE_FCI_IntPred Computes FCIs for a list of interval predictors
%COMPUTE_FCI_NomPred Computes FCIs for a list of nominal predictors
%Create_FCI_Report Calls the %Compute_FCI_NomPred and the %Compute_FCI_IntPred macros to compute the FCIs’ given input specifications

 

These macros provide a structured and automated approach for organizing, deploying, monitoring, and governing analytical models within SAS Model Manager, ensuring efficient model lifecycle management and governance.

 

Using PROC HTTP for Model Scoring in SAS Viya

 

SAS Viya provides powerful capabilities for deploying and scoring machine learning models through the microanalytic score service. The provided SAS code demonstrates how to interact with a REST API using PROC HTTP to retrieve available models, fetch scoring steps, and score a predictive model for car prices.

 

Step 1: Retrieve Available Models

The first section of the code retrieves the list of available scoring modules from MAS:

 

filename scores temp;
proc http
    url = "https://server.demo.sas.com/microanalyticScore/modules/"
    out= scores
    oauth_bearer = sas_services;
    headers
        'Accept'= 'application/vnd.sas.collection+json';
run;
libname scores clear;
libname scores json;

 

    • The PROC HTTP request calls the API endpoint for retrieving model modules.
    • The OAuth Bearer token (sas_services) ensures authentication.
    • The response, which is stored in the scores file, is converted into a SAS-readable JSON format using a libname json statement.
    • The ITEMS table under the scores library contains a list of available models. 01_xab_ModemaManager_ScoresItems.png
    • The ITEMS_LINKS table under the scores library contains a list of URIs which can be used to identify the endpoint which should be called for the steps02_xab_ModemaManager_ScoresItemsLinks.png

 

Select any image to see a larger version.
Mobile users: To view the images, select the "Full" version at the bottom of the page.

 

Step 2: Retrieve Scoring Steps for a Specific Model

After retrieving available models, the next step fetches the available scoring steps for a specific module named cars_msrp:

 

filename steps temp;
proc http
    url = "https://server.demo.sas.com/microanalyticScore/modules/cars_msrp/steps"
    out= steps
    oauth_bearer = sas_services;
    headers
        'Accept'= 'application/vnd.sas.collection+json';
run;
libname steps clear;
libname steps json;

 

  • This request queries the cars_msrp model to retrieve available steps.
  • The returned JSON response includes available scoring actions that can be applied to this model.
  • The ITEMS_LINKS table under the steps library contains a list of URIs which can be used to identify the endpoint which should be called to score the data. 03_xab_ModemaManager_StepsItemsLinks-1024x100.png
  • The ITEMS_INPUTS table under the steps library contains the list of parameters and relative types which should be passed to the model for scoring. 04_xab_ModemaManager_StepsItemsInputs-1024x346.png

 

Step 3: Prepare JSON Input for Scoring

To perform scoring, we must send input variables in JSON format. You can use the content of the ITEMS_INPUTS table to create the JSON file. The DATA _NULL_ step creates a JSON payload containing attributes:

 

filename results temp;
filename json_in temp;
data _null_;
    file json_in;
    input ;
    put _infile_;
    datalines;
    {"inputs":[
    {"name": "drivetrain", "value":"Front"},
    {"name": "origin", "value": "Europe"},
    {"name": "type", "value": "Sedan"},
    {"name": "cylinders", "value": 4},
    {"name": "enginesize", "value": 2.5},
    {"name": "horsepower", "value": 375},
    {"name": "length", "value": 170},
    {"name": "weight", "value": 1500},
    {"name": "mpg_highway", "value": 25},
    {"name": "mpg_city", "value": 20}]}
    ;
run;

 

  • This JSON structure defines the input variables required by the model.
  • It includes numerical and categorical features relevant to predicting car MSRP (Manufacturer’s Suggested Retail Price).

 

Step 4: Score the Model

The final step sends the JSON input data to the score step of the cars_msrp model and retrieves the prediction results:

 

proc http
    url = "https://server.demo.sas.com/microanalyticScore/modules/cars_msrp/steps/score"
    out= results
    method=POST
    in=json_in
    oauth_bearer = sas_services;
    headers
        'Accept'= 'application/vnd.sas.microanalytic.module.step.output+json'
        'Content-Type'= 'application/json';
run;
libname results clear;
libname results json;

 

  • PROC HTTP sends a POST request to submit the JSON input data.
  • The Content-Type header specifies that the request body is in JSON format.
  • The OAuth Bearer token ensures authentication.
  • The response containing the predicted car price is stored in results and converted into a readable JSON format for further analysis. 05_xab_ModemaManager_ResultsOutputs.png

 

Conclusion

 

Using the SAS Model Manager Macro variables, you can easily manage the analytic lifecycle from SAS Studio or using the SAS extension for Visual Studio Code. When you want to develop functionalities that are not available out of the box, you can use PROC HTTP to retrieve information using the SAS provided REST APIs.

 

The SAS code demonstrates a structured approach to querying available machine learning models, retrieving their scoring steps, and performing real-time model inference. The use of PROC HTTP enables seamless integration with SAS Viya’s REST APIs for predictive analytics. By automating these requests, organizations can efficiently deploy and utilize machine learning models within their SAS environment.

 

 

Find more articles from SAS Global Enablement and Learning here.

Contributors
Version history
Last update:
‎04-07-2025 03:04 AM
Updated by:

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

SAS AI and Machine Learning Courses

The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.

Get started