BookmarkSubscribeRSS Feed

What's New with SAS Model Manager? Enhanced support for R models

Started ‎01-08-2021 by
Modified ‎05-18-2021 by
Views 4,291

Do you code in R? Are you looking for a way to operationalize your R-based models? Look no further than SAS Model Manager.


SAS Model Manager streamlines model deployment and management, within a single tool, allowing users to operationalize SAS and open-source models with ease and speed. One of our primary product development themes focuses on Open Model Deployment. SAS Model Manager is dedicated to creating software that provides users the ability to evaluate, publish, and monitor all open-source models. In fact, SAS Model Manager allows you to organize and manage all types of analytic models and pipelines.


Glenn Clingroth, Senior R&M Development Manager, says it best in his SASGF2020 paper entitled "Open-Source Model Management with SAS® Model Manager". A major goal for SAS Model Manager is treating open-source models as first-class models that can be part of the entire model life cycle. This means they can be tested, deployed, and monitored either on their own, or alongside SAS models. SAS Model Manager has evolved to provide this functionality, and by providing the ability to publish models to standalone docker containers, it's possible to deploy the models to open-source environments.


New function details

Our efforts to drive Open Model Deployment started with Python-based model support. The journey began with SAS Model Manager on SAS Viya 3.5 (15.3), where we  enhanced Python support for SAS Open Model Manager, and made further enhancements with the SAS Model Manager 2020.1 release. When importing Python-based models into SAS Model Manager, we automatically generate executable scoring code for use with SAS scoring engines.​ This enables users to test models and validate model scoring logic before deployment into multiple production destinations using a precise methodology and a system that automatically records each test the scoring engine performs.


Additionally, we created pzmm (also known as Python Zip Model Management module) to move through the process of importing Python models into SAS Model Manager, while using native Python code to submit REST API requests to the Model Repository API. Please see the pzmm (Python Zip Model Management) module updates article for more details about how SAS Model Manager supports Python-based models.


With the December 2020.1.1 release, we've enhanced R-model support. When you import an R-based model with a scoring function, we automatically generate an RPy2 and DS2 executable wrapper scoring code for use with SAS scoring engines. It's easy for users to run an on-demand scoring test for their R-model. Plus they can deploy their R-model to one of the following model publishing destinations for scoring and validation.

  • SAS Cloud Analytic Service (CAS), or
  • run-time containers such as Amazon Web Services (AWS), Azure, or Private Docker containers.


Functionality in action

Here's a video showcasing SAS Model Manager's enhanced R-model support:



And code

Here's an example of an R model score code containing a scoring function for SAS's traditional HMEQ dataset:


    # Threshold for the misclassification error
    threshPredProb <- 0.0922431865828092

    # Impute the training data means for missing values
    CLAGE[] <- 184.46319669399
    CLNO[] <- 21.45890861275

    # Impute the training data medians for missing values
    DEBTINC[] <- 34.84415543351
    DELINQ[] <- 0.0
    DEROG[] <- 0.0
    NINQ[] <- 0.0
    YOJ[] <- 7.0

    # Impute the training data modes for missing values
    JOB[ || is.null(JOB) || trimws(JOB) == ""] <- "Other"
    REASON[ || is.null(REASON) || trimws(REASON) == ""] <- "DebtCon"

    # Create the dummy variables for the factors JOB and REASON
    # Other is the reference category for JOB
    JOB.Mgr <- ifelse(JOB == "Mgr", 1, 0)
    JOB.Office <- ifelse(JOB == "Office", 1, 0)
    # JOB.Other <- ifelse(JOB == "Other", 1, 0)
    JOB.ProfExe <- ifelse(JOB == "ProfExe", 1, 0)
    JOB.Sales <- ifelse(JOB == "Sales", 1, 0)
    JOB.Self <- ifelse(JOB == "Self", 1, 0)

    # DebtCon is the reference category for REASON
    # REASON.DebtCon <- ifelse(REASON == "DebtCon", 1, 0)
    REASON.HomeImp <- ifelse(REASON == "HomeImp", 1, 0)

    input_array <- data.frame("JOB.Mgr" = JOB.Mgr, "JOB.Office" = JOB.Office, "JOB.ProfExe" = JOB.ProfExe,
                              "JOB.Sales" = JOB.Sales, "JOB.Self" = JOB.Self,
                              "REASON.HomeImp" = REASON.HomeImp, 
                              "CLAGE" = CLAGE, "CLNO" = CLNO, "DEBTINC" = DEBTINC, "DELINQ" = DELINQ,
                              "DEROG" = DEROG, "NINQ" = NINQ, "YOJ" = YOJ)
    predProb <- predict(myLogistic, newdata = input_array, type='response')

    # Retrieve the event probability
    EM_EVENTPROBABILITY <- predProb[1]

    # Determine the predicted target category
    EM_CLASSIFICATION <- ifelse(EM_EVENTPROBABILITY >= threshPredProb, "1", "0")



View from the GUI

When registering R model score code into SAS Model Manager 2020.1.1 and future, expect to see a file within your model files. Here's an example based on the Stepwise Logistic R model shown in the video.




Great news...if you make a mistake you can edit your score code directly within SAS Model Manager's GUI. All wrappers (including rPy2 and DS2 wrappers) are created on an as-needed basis. As a result, the code reflects any changes...and fixes...when used for scoring purposes.


Supporting resources

To help users create their R model score code, with the correct scoring function format, please check out these samples posted to our GitHub project. 

Additionally, we've uploaded two R model helper functions. 


The export_binary_model.r was used in the video example.

The export_binary_model() function expects the following files are in the jsonFolder:

  1. analysisPrefix_train.r
  2. analysisPrefix_r_score.r
  3. analysisPrefix_r.rds


For additional support about SAS Model Manager's focus on Open Model Deployment, please see our Model Management Resources for Open-Source Models GitHub project. This repository contains resources for administration and customizations that help with managing open-source models. There are sample models and data, aw well as example Jupyter notebooks to submit API requests for common model management tasks using SAS Model Manager or SAS Open Model Manager.


For more information, see R Models in SAS Model Manager: User’s Guide.


Interested to learn about other SAS Model Manager features? Please refer to other "What's new with SAS Model Manager?" posts including:




Version history
Last update:
‎05-18-2021 09:42 AM
Updated by:


Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.


Register now!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started

Article Tags