0% found this document useful (0 votes)
51 views

PRESENTATION - Ask The Expert - How Do I Integrate SAS Viya and Open Source

How Do I Integrate SAS Viya and Open Source

Uploaded by

Alexandre Alves
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

PRESENTATION - Ask The Expert - How Do I Integrate SAS Viya and Open Source

How Do I Integrate SAS Viya and Open Source

Uploaded by

Alexandre Alves
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 121

How do I Integrate SAS Viya and

Open Source
Ask the Expert

Melodie Rush
Customer Success Principal Data Scientist
Connect with me:
LinkedIn: https://www.linkedin.com/in/melodierush
Twitter: @Melodie_Rush

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


01 Pipelines in Model Studio

02 SWAT in Jupyter Notebooks

03 Models in Model Manager

AGENDA Additional Open Source


04 Integration

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


What is SAS Viya?
SAS Viya is a cloud-enabled, in-memory analytics engine that provides
quick, accurate and reliable analytical insights.

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


SAS Viya Products
SAS Viya takes advantage of a cloud-enabled, open platform. Most offerings include
both a coding interface as well a visual interface.
• SAS Visual Analytics • SAS Data Preparation
• SAS Visual Statistics • SAS Visual Investigator
• SAS Visual Data Mining and • SAS Business Analytics
Machine Learning • SAS Intelligent Decisioning
• SAS Visual Forecasting • SAS Cybersecurity
• SAS Visual Text Analytics • SAS Detection and Investigation
• SAS Optimization • SAS Event Stream Processing
• SAS Econometrics • And more…
• SAS Model Manager

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Visual Interfaces

Programming Interfaces

API Interfaces

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Model Studio Pipelines
Open Source Code Node

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


SAS Visual Data Mining and Machine Learning (VDMML)
• Automated modeling with pipelines
Build Models – In Model Studio

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Demo Pipelines in
Model Studio

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Open Source Code node in Model Studio
is located under Miscellaneous

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Open Source Code Node

• Python or R code
• Downloads a sample of data
to CAS controller
• Runs code natively in Python
or R installed on the CAS
controller
• Brings results back to CAS for
comparison in Model Studio

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Open Source Code Node
Preprocessing or Supervised Learning

(in Supervised Learning lane)

(in Preprocessing lane)

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Python or R setup instructions
• The node is agnostic to Python or R software versions; any version can be used as
the code is passed along
• Python or R should be installed on the SAS Compute Server
• The node executes with privileges of the user logged in

• Executables in system PATH


– python
– Rscript
• When PYTHONHOME or RHOME system environment variables are defined
– %PYTHONHOME%/python
– %RHOME%/bin/Rscript

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Open Source Code
Node
And its properties

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Node properties – Data Sample

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Node Properties - Data Sample
Use caution and avoid movement of large amounts of data
• Downloads data sample from
CAS as CSV file (node_data.csv)

• Default is stratified sample of


10,000 observations
– Stratified by partition variable or
class target when applicable

• NOTE that this node is using a


sample when performing Model
Comparison
Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.
Node properties – Code editor

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Node Properties - Code editor

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Under the covers, various code snippets are appended

1. Precursor code

2. Precursor code: Create data


frame=Yes

3. USER CODE

4. Posterior code: Create data frame=Yes;


Supervised Learning lane

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


1. Precursor code
Python

#-------------------------------------------------------------------------------
# Language: PYTHON node’s working directory
#-------------------------------------------------------------------------------
# Variable declarations
dm_nodedir = '/xxx/xxx/xxx/xxx'
dm_dec_target = 'BAD'
dm_partitionvar = '_PartInd_'
dm_partition_train_val = 1

dm_class_input = ["IMP_DELINQ","IMP_DEROG","IMP_JOB","IMP_NINQ","IMP_REASON"]
dm_interval_input = ["IMP_CLAGE","IMP_CLNO","IMP_DEBTINC","IMP_MORTDUE","IMP_VALUE","IMP_YOJ" ,"LOAN"]
dm_input = dm_class_input + dm_interval_input

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


1. Precursor code
R
#-------------------------------------------------------------------------------
# Language: R node’s working directory
#-------------------------------------------------------------------------------
# Set R-work to node-work directory
dm_nodedir <- '/xxx/xxx/xxx/xxx'
setwd(dm_nodedir)

# Variable declarations
dm_dec_target <- 'BAD'
dm_partitionvar <- '_PartInd_'
dm_partition_train_val <- 1

dm_class_input <- c("IMP_DELINQ","IMP_DEROG","IMP_JOB","IMP_NINQ","IMP_REASON")


dm_interval_input <- c("IMP_CLAGE","IMP_CLNO","IMP_DEBTINC","IMP_MORTDUE","IMP_VALUE","IMP_YOJ" ,"LOAN")
dm_input <- c(dm_class_input, dm_interval_input)
dm_model_formula <- as.formula(paste(dm_dec_target, '~', paste(dm_input, collapse='+')))

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Node properties – Generate data frame

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


2. Precursor code
Python: Generate data frame = Yes

#-------------------------------------------------------------------------------
# Generate data frame: Y
#-------------------------------------------------------------------------------
import pandas as pd
dm_inputdf = pd.read_csv(dm_nodedir + '/node_data.csv')

dm_traindf = dm_inputdf[dm_inputdf[dm_partitionvar] == dm_partition_train_val]

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


2. Precursor code
R: Generate data frame - Yes

#-------------------------------------------------------------------------------
# Generate data frame: Y
#-------------------------------------------------------------------------------
dm_inputdf <- read.csv(file='node_data.csv', stringsAsFactors=TRUE, check.names=FALSE)

# Change class variable type to R factor


dm_inputdf$BAD <- factor(dm_inputdf$BAD, ordered=FALSE)
dm_inputdf$IMP_DELINQ <- factor(dm_inputdf$IMP_DELINQ, ordered=FALSE)
dm_inputdf$IMP_DEROG <- factor(dm_inputdf$IMP_DEROG, ordered=FALSE)
dm_inputdf$IMP_NINQ <- factor(dm_inputdf$IMP_NINQ, ordered=FALSE)

dm_traindf = subset(dm_inputdf, get(dm_partitionvar) == dm_partition_train_val)

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


4. Posterior code
Python: Generate data frame = Yes; Supervised Learning lane

#-------------------------------------------------------------------------------
# Generate data frame: Y; Supervised model
#-------------------------------------------------------------------------------
dm_scoreddf.to_csv(path_or_buf=dm_nodedir + '/node_scored.csv', encoding='utf-8', index=False,
float_format='%g')

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


4. Posterior code
R: Generate data frame = Yes; Supervised Learning lane

#-------------------------------------------------------------------------------
# Generate data frame: Y; Supervised model
#-------------------------------------------------------------------------------
write.csv(dm_scoreddf, file='node_scored.csv', row.names=FALSE, fileEncoding='UTF-8')

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Executed code has included

Precursor, User and Posterior code 1. Precursor code


snippets appended together
2. Precursor code: Create data
frame=Yes
If Create data frame property is not
selected, there will be no snippets for 3. USER CODE
(2) and (4)
4. Posterior code: Create data frame=Yes;
Supervised Learning lane

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Node Results

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Pipelines – Python or R
Preprocessing

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Pipelines – Python or R
Preprocessing – Python Code

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Pipelines – Python or R
Preprocessing - Results

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Moving to Supervised
Learning Lane

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


To use for Supervised Learning
For comparing with other models in pipeline

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Moving the node to Supervised Learning lane
For model assessment
• Move to Supervised Learning lane
when training a model that has
predictions available

• Model assessment is performed


automatically if predictions are
1. Saved in dm_scoreddf data frame or
node_scored.csv
2. Prediction variables are named according
to below convention**
• P_<targetVarName> for interval target
• P_<targetVarName><targetLevel> for class BAD is binary target with levels 0 and 1
targets; all target level probabilities should
be computed targetVarName = BAD
targetLevel = 0 or 1
Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.
Results from Python or R execution can be viewed
in the node when
• Saved with rpt_ prefix
– Tables can be saved with csv file extension where first row is header
E.g., rpt_<filename>.csv
– Images can be saved in png, jpeg, jpg, gif formats
E.g., rpt_<filename>.png
– Plain text files can be saved with txt file extension
E.g., rpt_<filename>.txt

• rpt_ prefix is not case-sensitive


• rpt_ prefix and file extensions (.csv, .txt, .png, .jpeg, .jpg, .gif)
are key in identifying which files to display

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Pipelines – R Code
Supervised Learning

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Pipelines - R Code
Supervised Learning

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Pipelines – R Code
Supervised Learning

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Pipelines – R Code
Supervised Learning

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Pipelines – Python Code
Supervised Learning

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Pipelines – Python Code
Supervised Learning

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Pipelines – Python Code
Supervised Learning

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Pipelines – Python Code
Supervised Learning

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Performing model comparison
When executing in Supervised Learning

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Demo Open Source
Code Node

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Tips for Using the Open
Source Code Node

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


How Do I . . . In the Open Source Code Node?
• How do I access the input data?
– Use the macro variable dm_inputdf as a data frame and specify
‘Drop rejected variables’ in the node properties pane.
• How do I save the model?
– Name the model dm_model.
• How do I save the output data?
– Score the data using your model and saved the scored data
frame with the name dm_scoreddf and specify ‘Use output data
in child nodes’ in the node properties pane.
• How do I print to the results?
– Print(“string you want to print”)
– Print(object_you_want_to_print)
• How do I add a plot to the results?
– Import matplotlib as plt
Plt.plot( . . . )
Plt.savefig(dm_nodedir + ‘/rpt_name_for_plot.png’)

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Tips for using the Open Source Node

To add Python
code to every
Open Source Code
node use Project
Settings → Node
Configuration

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Tips for using the Open Source Node

Remember to include an Imputation node


to handle missing values before using the
Open Source Code node for Supervised
Learning.

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Debugging the Open
Source Code Node

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Debugging in Model Studio
Right-click the node and select ‘Log’

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Debugging in Model Studio
Click the first ‘Error’

This is the error returned by SAS and it is not descriptive. Clicking it will move the log to where the error
occurred.
Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.
Debugging in Model Studio
Scroll up to find the output returned by python

This will tell you which line of code encountered the error and what the error was – in this case an
indentation error.
Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.
Summary

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Open Source Code node
CAN
• Support execution of Python/R code
– Downloads data sample from Cloud Analytic Services (CAS)

• Display results from Python/R code execution

• Produce assessment statistics of Python/R models

• Enable comparison of Python/R models within Model Studio pipeline

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Open Source Code node
CAN NOT

Support Register,
Be part of an Publish or
Ensemble Download score
code or score API

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


SWAT in Jupyter Notebooks (or R Studio)
Open Source Programming and Viya

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Open Source Programming
Three Important Open Source Packages

SAS Scripting Wrapper for Analytics Transfer SWAT for Python GitHub
(SWAT) allows you to access data stored on SWAT for R GitHub
Viya and use Viya-enabled procedures from
Viya Programming Guide
Python and R.

SASCTL allows you to push models developed SASCTL GitHub


in Python (SWAT and pure-Python) into SAS Additional information for importing Open Source
Model Manager on Viya. Models into Model Manager.

PZMM is a new Python package that will


absorb and expand the functionality of Open Model Manager Resources GitHub.
SASCTL.

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Open Source Programming
Analytics Process Flow

Import Connect Load Access Clean Save Create


Import Connect to Load SWAT Access Data Clean data, Save model Create
packages CAS via SWAT, actions, in Upload data perform into Model necessary files
including in example: example: to notebook, analytics, Manager via for
SWAT, PMZZ, •sas = •sas.builtins.load in example: create SASCTL comparison
and SASCTL swat.CAS('localh actionset('decisi models. using PZMM.
ost', 5570, onTree') Access in-
authinfo='~/.aut memory
hinfo', tables in CAS,
caslib="CASUSE
R")
in example

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


SWAT
For R and Python

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


SAS® Scripting Wrapper for Analytics Transfer (SWAT)
Python and R
• Integration of SAS® Analytics in Python and R
code
• R Studio and Jupyter Notebook support
• SWAT packages are available for Python and R
free on GitHub or developer.sas.com.
• Download and install SWAT, connect to a CAS
server, then write code to drive CAS actions.
• The SWAT package mimics much of the APIs of
the native packages making it an easy addition
for programmers familiar these languages.

Open to SAS®

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


proc print data = x.hmeq (obs = 10);
run;
Workers

Controller
APIs

df = s.CASTable(‘hmeq’)
df.head(10)

CAS Action
[table.fetch]
table.name = “hmeq”
from = 1 to = 10

df <- defCasTable(s, ‘hmeq’)


head(df, 10)

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


The SWAT Package
Gives unique Python & R functions to perform licensed CAS actions. The
functionality mimics the look and feel of Python & R syntax, making it easy
for Python & R users to take advantage of CAS.
Action Sets
Actions
Parameters
Options

sas.decisionTree.forestTrain(
table = dict(),
target = string,
inputs = value_list,
nominals = value_list,
ntree = int32,
casOut = dict()
)
Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.
R SWAT example

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


An Example Flow for R SWAT Interface to CAS
Import Packages

Connect to CAS Session

Load data into CAS

Print 5 rows

Check for Missing

Use R to plot results

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


SWAT R
Import packages and connect to CAS Session
Import needed packages

Connect to SAS CAS Session

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


SWAT R
Load data into CAS
Load data

Look at the data

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


SWAT R
Check for Missing Values

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


SWAT R
Use R to plot resulting tables

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Python SWAT example

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


An Example Flow for Python SWAT Interface to CAS
Import Packages

Connect to CAS Session

Load data into CAS

Import CAS Action Sets

Use CAS Action Sets for


Cardinality

Use Python to plot resulting


tables

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


SWAT Python
Import packages and connect to CAS Session
Import needed packages

Connect to SAS CAS Session

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


SWAT Python
Load data into CAS
Load data

Look at the data

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


SWAT Python
Import CAS Action Sets

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


SWAT Python
Use SAS Action Sets for Cardinality

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


SWAT Python
Use Python to plot resulting tables

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Demo SWAT

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Summary

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


SWAT
CAN
• Support execution of Python or R code
– Connects to SAS CAS to run SAS Actions

• Can be used with IDE’s such as Jupyter Notebooks and R Studio

• Python/R runs where IDE’s are configured either locally or on compute


server

• Mix SAS programming with Open Source (Python or R)

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


SAS Model Manager
And SAS Open Model Manager

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


SAS Model Manager

Register

Validate

Deploy

Monitor

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Register
Organize & Manage Analytic Models/Pipelines

• Central, searchable repository


forall models/pipelines
• Compare models side-by-side
• Version control and track
project history

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Validate
Test Auto-Generated Executable Score Code

• Automatically generate
executable scoring code for
Python-based models
• Validate model is executable,
using representative test data set
• View output table, code, and log
• Publish Validation ensures model
is executing correctly in
production environment

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Deploy
Model Publishing & Scoring
• Quick and easy access to different
production environments
• Deploy in-batch, streaming, cloud or
edge device
• NEW Azure Container Publishing
Destination for Open Source models
• Supported publishing destinations
include SAS Cloud Analytic Services
(CAS), Apache Hadoop, SAS Micro
Analytic Service (MAS), Teradata, as
well as container destinations such
as Amazon Web Services, Azure, and
Private Docker

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Monitor
Monitor Model Performance

• New wizard to simply generation


of out of the box performance
reports
• Performance-monitoring tasks
including data source changes,
score value changes, model
accuracy over multiple time
periods, and new input/output
variable feature contribution plot
• Users can access the data to
generate their own reports

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


SASCTL

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Model Management in REST format
in addition to actions from GUI

Each action in Model Can be done using REST calls to


Manager HTML visual Model Manager as well
interface + options in REST only

• Easy to track underlying RESTs for actions at browser


• Publicly available docs on REST API + examples
• Some Workflow Management actions are available only via REST
• sasctl – publicly available package for Model Management at GitHub
Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.
sasctl package
sasctl package
Functionality Overview
1. Sessions – connect to the Viya server. This connection is made to the REST
endpoints of the Viya microservices, not to CAS.
2. Tasks – commonly used functionality. For example, the register_model
task makes REST calls to perform the following functions
• lookup a repository
• lookup a project
• create a project
• create a model
• import a model
• upload a file
3. Services – essentially Python representations of the Viya REST services

Github Documentation and Examples


Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.
sasctl package
Why translators are helpful?

sasctl
translation

.pkl SAS data step


pip install sasctl
pyml2ds(in_path, out_path, target_var_name)

• Work with algorithms, disabled by PMML translation (e.g. highly


demanded boosting)
• Now available: XGboost, LightGBM, h2o GradBoost.
• New translator’s creation is quite fast, available on request
• Translated models have the same governance options as native SAS
models (except retrain)
Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.
pzMM

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Register Python Models using pzMM
pickleZip-mm

• Simplifies registration of Python model


into SAS Model Manager & SAS Open
Model Manager
• Use pzMM to
– write executable score.py file and
supporting metadata JSON files
– serialize trained model into binary pickle
file, and
– archives all relevant model files into a ZIP
file and imports using REST API calls for
deployment and governance needs

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Summary
SAS Model Manager

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


SAS Model Manager
CAN
• Supports the registration, validation, deployment
and monitoring of Python and R models
• Available using both the point and click in the visual
interface and through programming using packages
sasctl and pzmm

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Other Integration
REST APIs, PROC FCMP, SAS JAVA Object

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


REST APIs

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


REST APIs
What is a REST API?

An API is the messenger that takes a request, tells a system what you
want to do and then returns the response back to you.
• A RESTful API is an application program interface (API) that uses HTTP
requests to GET, PUT, POST and DELETE data. An API for a website is
code that allows two software programs to communicate with each
other.
• “REST stands for REpresentational State Transfer”
• “API means Application Programming Interface”

SAS Viya: Working with APIs – Ask the Expert


Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.
REST APIs
Two entry points into SAS Viya

APIs for application developers APIs for analysts and data scientist
and admins • Designed for data scientist,
• designed for enterprise programmers and administrators
application developers who need to interact with CAS
• intend to build on the work of directly
model builders and data • Used to executing CAS actions,
scientists, to deliver apps based managing CAS sessions,
on SAS Viya technology monitoring the system and
inspecting the CAS grid

developer.SAS.com
Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.
REST APIs
Scoring API

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


REST APIs
Scoring API

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


REST APIs
APIs for analysts and data scientist

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


REST APIs
APIs for analysts and data scientist

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


REST APIs
Examples available on GitHub

REST API Examples on github

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


PROC FCMP

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


PROC FCMP
What is it?
• SAS Function Compiler
• Enables you to create, test, and store SAS functions, CALL routines, and
subroutines before you use them in other SAS procedures or DATA steps

PROC FCMP Documentation


What’s New in FCMP for SAS 9.4 and SAS Viya

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


PROC FCMP
Python Objects

• Python objects enable you to embed and import Python functions into SAS
programs
• The Python code is not converted to SAS code. Instead, the Python code runs in
the Python interpreter of your choice and returns the results to SAS.
• With a small Python code modification, you can run your Python functions from
SAS and easily program in both languages at the same time.

Using Python functions inside of SAS Programs


Using Python Functions in PROC FCMP
Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.
FCMP Statements

• SUBMIT INTO - Write a block of Python code into the Python object
• APPEND – write a single line of Python code into the Python object
• PUBLISH – taking the source code in our Python object and submitting
it to the Python interpreter
• CALL – accessing the Python function in SAS Data Step or PROC FCMP
• CLEAR – Python object is cleaned of all knowledge of any previous
Python source code

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


FCMP SUBMIT INTO
Example
submit into py;
def pricing(reason, price, discount):
"Output: newprice, mark"
if reason.upper() == "MARKDOWN":
newprice = price *(1-(discount+0.05))
mark="MARKDOWN"
else:
newprice = price *(1-0.05) mark="STANDARD“
return newprice, mark
endsubmit;

submit into py("c:\PythonSource\BlackScholes.py ");

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


FCMPACT Action Set
Allows you to create custom functions and subroutines within SAS Viya

• addRoutines – add FCMP functions or subroutines to a CAS table


• runProgram – execute FCMP code
• loadFcmpTable – load a single FCMP function table into memory
• loadFcmpLibs – load all FCMP tables in the session CMP library
memory

FCMP Action Set Documentation

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


FCMPACT Action Set
Store FCMP Subroutines into CAS
proc cas;
session mysession;

/* Load the FCMP action set in the usual way */


loadactionset "fcmpact";

/* Add two FCMP subroutines to CASUSER.SUBRTN */


action addRoutines /
routineCode = " subroutine hometown(city $, state $, returnstr $);
subroutine math1 (a, b, c); outargs returnstr;
outargs b,c; returnstr = 'My hometown is: ' || ktrim(city) || ', ' || ktrim(state);
b = a; endsub;"
c = a + b*b; package = "pkg"
endsub; saveTable=1
funcTable = {caslib="CASUSER" name="SUBRTN" replace=1};
quit;

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


FCMPACT Action Set
Run an FCMP Program in CAS
proc cas;

/* Run an FCMP program in CAS, calling our SUBRTN library */


action runProgram /
routineCode = "
length residence $60;
call math1(x, y, result);
call hometown(city, state, residence);"

/* Program is called on each row of input data */


inputData={caslib="CASUSER" name="cityandnum"}

/* Program results are written to the output table */


outputData={caslib="CASUSER" name="outdta" replace=1};
quit;
Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.
Base SAS Java Object

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Base SAS Java Object
Executes a Python or R file

• Allows you to pass a Python or R executable file to the Java class SASJavaExec
• SASJavaExec runs the Python or R script with its command line argument and
passes any output or reports any errors back to the SAS Viya log
• Useful if
– Need to submit a Python or R script to a compute server or remote environment
– Want to include DLPy models in a pipeline

Using Python with Model Studio for SAS Visual Data Mining
and Machine Learning – Paper
Incorporating Python into your SAS Visual Data Mining and
Machine Learning Pipeline - Video
Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.
Base SAS Java Object
Executes a Python or R file
/* Execute Python script */
data _null_;
length rtn_val 8;
declare javaobj
j("com.sas.analytics.datamining.servertier.SASPythonExec",
"&dm_nodedir&dm_dsep.dm_srcfile.py");
j.callVoidMethod("setOutputFile",
"&dm_nodedir&dm_dsep&lang._output.txt");
j.callIntMethod("executeProcess", rtn_val);
j.delete();
call symput('javaobj_rtnval', rtn_val);
run;

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Resources
Where to learn more

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


SAS Visual Data Mining and Machine Learning
Try it for free!
• VDMML Free Trial:
https://www.sas.com/en_
us/software/visual-data-
mining-machine-
learning.html
• VDMML Documentation:
https://support.sas.com/d
ocumentation/prod-
p/vdmml/index.html

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Pipelines in Model Studio
Open Source Node

• GitHub Open Source Code Node


Resources
• Executing Open Source Code in SAS
Visual Data Mining and Machine
Learning Pipelines (video)
• Open Source Code Node
Documentation
• Open Source Code Node Example

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Pipelines in Model Studio
SWAT
• SAS Github page for SWAT-Python
• SAS Github page for SWAT-R
• More example scripts for using SWAT-R & SWAT-Python
• Viya and Python Example (video)
• Viya Machine Learning GitHub
• SAS APIs for Other Languages (Videos)
• Getting Stated with Python Integration to SAS Viya (Blog Series)

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Pipelines in Model Studio
Programming
• CAS actions documentation
• Viya Programming Guide
• Viya Programming GitHub
• Getting Started with SAS Viya for Python
• Getting Started with SAS Viya for R
• Downloading Batch API

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Pipelines in Model Studio
SAS Model Manager
• Open-Source Model Management with SAS Model Manager
• SAS Model Manager documentation
• SAS Open Model Manager documentation
• Demo videos
• Examples
• SASCTL Examples

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Pipelines in Model Studio
Other Integration
• SAS Viya: Working with APIs – Ask the Expert
• SAS and Open Source: Two Integrated Worlds
• Using Python with Model Studio for SAS Visual Data Mining and Machine Learning – Paper
• Incorporating Python into your SAS Visual Data Mining and Machine Learning Pipeline –
Video
• What’s New in FCMP for SAS 9.4 and SAS Viya
• PROC FCMP Documentation
• Using Python functions inside of SAS Programs
• Using Python Functions in PROC FCMP
• Developer.sas.com for REST APIs
• REST API Examples on github

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Questions?
Thank you for your time and attention!

Connect with me:


LinkedIn: https://www.linkedin.com/in/melodierush
Twitter: @Melodie_Rush

sas.com

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.


Explore Helpful Resources
Ask the Expert
View other user webinars that provide insights into using SAS products to make your job easier.

FREE Training
Learn from home – free for 30 days. Get software labs to practice and online support if needed.

SAS Support Communities


Ask questions, get answers and share insights with SAS users.

SAS Analytics Explorers


An exclusive platform to collaborate, learn and share your expertise. Gain access to a diverse network to advance your career. Special
rewards and recognition exclusively for SAS users.

SAS Users YouTube Channel


A plethora of videos on hundreds of topics, just for SAS users.

Newsletters
Get the latest SAS news plus tips, tricks and more.

Users Groups
Meet local SAS users, network and exchange ideas – virtually.

SAS Profile
If you haven’t already done so, create your SAS Profile to access free training, SAS Support Communities, technical support, software
downloads, newsletters and more.

Copyr i ght © SAS I nsti tute I nc . Al l r i ghts reser ved.

You might also like