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).
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.
%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 |
%MM_PERFORMANCE_MONITOR | Defines and runs performance monitoring for a champion or challenger model |
%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 |
%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.
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.
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;
Select any image to see a larger version.
Mobile users: To view the images, select the "Full" version at the bottom of the page.
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;
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;
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;
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.
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!
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.