Hello, I am Jagruti Kanjia
from the Advanced Analytics
Division of SAS.
In this video, I demonstrate
how you can generate models
based on SAS Viya procedures
within SAS Enterprise Miner.
Using the SAS Viya Code node,
you can run procedures in CAS
and have the results displayed
in SAS Enterprise Miner.
Starting with the
SAS 9.4M5 release,
the SAS 9.4 client can take
advantage of a CAS server
in a SAS Viya environment.
This means that you don’t
have to choose between SAS 9.4
and SAS Viya.
You can use a single
SAS 9.4 client
to run SAS 9.4 code
on a SAS 9.4 server
and to run a SAS Viya
procedure on a CAS server, all
within the same program.
Any SAS Viya procedure that is
encountered by either engine
is executed on the CAS server.
The SAS Viya code node
in SAS Enterprise Miner
can be used to create models
based on SAS Data Mining
and Machine Learning procedures.
Using the SAS Viya
Code node, you
can run SAS Viya
procedures in CAS
and have the results displayed
in SAS Enterprise Miner.
Models generated in
the SAS Viya Code node
can be also compared
to other models
based on traditional SAS
Enterprise Miner nodes.
The SAS Viya Code editor
provides a macro toolkit
and code template
to get you started
writing the code you need to run
Viya procedures in CAS from SAS
Enterprise Miner.
Various utility
macros are provided
that enable you to establish a
connection to the CAS server,
load data into CAS, assess
models, do model selection
and produce custom
reports similar to what
we are used to seeing
from SAS Enterprise Miner.
The Training Code editor
in the SAS Viya Code node
consists of a template
with a section where you
can enter your custom SAS Code.
The %em_viya_signon macro
establishes a connection
to the CAS server using
the information specified
in the properties.
We first need to provide the
name and port of the SAS Viya
machine, the name of the
CAS library (CASLIB),
and the name of the CAS user.
The arguments for the caslib
and casuser macro variables
define the caslib where
the data are loaded.
You must provide login
credentials in each SAS Viya
Code node that you create.
The %em_viya_signon macro
creates a CAS session
and assigns the CAS library.
The %em_viya_dataprep macro
prepares the training data
and uploads these data
to the CAS server.
The %em_viya_setmacrovars macro
initializes macro variables
for target information, input
variables, utility macros,
and files.
For example, the
em_partition_statement macro
variable can be used to write
a partition statement in a SAS
Viya procedure.
Use the EM_REGISTER macro to
register a unique file key.
When you register a key, SAS
Enterprise Miner generates
macro variable
named &EM_USER_key.
You then use &EM_USER_key in
your code to associate a file
with the key.
The em_viya_setMacroVars
macro creates macro variables
in SAS Viya for
each table or file
that is specified using the
Enterprise Miner EM_REGISTER
macro.
The %em_viya_setmacrovars macro
processes assessment tables,
as well as table and files
specified via the %em_register
macro and downloads them to the
EM diagram and node folders.
Any tables created in CAS are
downloaded to the EMWS folder
directory in SAS 9.4.
Any table or file
created in SAS is
downloaded to either the Node
folder or the EMWS folder.
The %em_viya_assess macro
submits a proc assess step
to generate applicable
assessment statistics,
such as fit statistics,
lift and if applicable,
ROC (Receiver operating
characteristic) tables.
The macro assumes that
the appropriate posterior
probability or
predicted variables
are produced by the score code.
The model score code can be
DS1 or an Analytic Store.
The %em_viya_modelselection
macro compares models that were
run in the same node and
determines the best model
according to the criterion
specified by the Class
Selection Statistics and
Interval Selection Statistics
properties.
The score code or analytic
store for the best model
is downloaded to SAS
Enterprise Miner.
It is used to assess the
SAS Enterprise Miner data
and is exported by the node.
The %em_viya_terminate
macro, which is included
in the template,
terminates the CAS session.
This is a best practice.
The specific business
problem we are
trying to solve in this example
is increasing company profits
at the fictitious
Insight Toy Company.
The goal is to
determine which features
are most likely to predict
whether a product was returned.
We created the Insight
Toy Company data source
and set Order Returned
as the target variable.
We are using the SAS
Code node to create
training and partition
data sets based
on a pre-defined
partition variable,
and we are using the
Transform Variables node
to create a new variable
called TotalCost
by adding OrderDistributionCost,
OrderMarketingCost,
OrderProductCost, and
OrderSalesCost variables.
In this example, we will use
the SAS Viya Code node to run
four models in our CAS session.
All models will be
assessed in SAS Viya using
the %em_viya_assess macro.
The name argument is used
so that we can clearly
identify the models when
comparing the assessment
results.
This macro must be called
after each model is run.
The %em_viya_modelSelection
macro will be used to select
the best models from the models
that have been assessed using
the %em_viya_assess macro.
We will compare the SAS Viya
model with the Regression
and Neural Network models
created by two traditional SAS
Enterprise Miner nodes: the
Regression node and the HP
Neural node.
We want to display some
results in the node,
so we need to register the
associated results tables.
This will ensure that the
results tables are downloaded
from the SAS Viya machine
to the SAS Enterprise Miner
diagram and node folders.
The CAS argument
is used to indicate
that these tables are in CAS.
A neural network
model is generated
using the NNET procedure.
We are using the
autotune feature
to autotune
optimization parameters.
The score code file
that is identified
by the %em_file_scorecode macro
contains DS1 code that will be
used to score the
training table.
The %em_viya_assess macro
with the name argument is used
to assess the Neural
Network model.
The proc nnet call
is submitted to CAS.
As you can see the
%em_interval_inputs
and %em_nominal_inputs
macros are resolved to a list
of interval variables and
a list of nominal variables
in the input statement.
The %em_partition_statement
macro variable resolved
to the partition
rolevar= statement.
Proc forest is used to
build the Forest model.
The outmodel statement creates
the outmodel table in CAS
which will be downloaded
to the SAS system
and will be used to display
a report in the node results.
We use the ODS statement to
create the varimportance1 table
that we will use to display
a report in the node results.
The FOREST model produces
an analytic store
using the SAVESTATE statement.
The analytic store will be used
to score the training table.
This remote analytic
store table will
be downloaded to
SAS Enterprise Miner
in the form of a binary file.
Proc gradboost is used to create
the Gradient Boosting model
and proc treesplit is used to
create the Decision Tree model.
Proc gradboost creates the
Analytic Store model and proc
treesplit creates the DS1 model.
Finally, we use the %em_report
macro to define reports to be
displayed in the results
viewer of the node.
In this example, we simply
display tabular reports.
The %em_viya_report macro
processes assessment tables
and score code, as well as
table and files specified via
the %em_register macro and
downloads them from the SAS
Viya machine to the EM
diagram and Node folders.
The results window
contains many reports
that you can use to
compare the various models.
These reports are
based on the data
that were assessed in SAS Viya
using the ASSESS procedure.
The report titled SAS Viya
Model Selection identifies
the model that was selected
according to the specified
criteria.
In this example, the
KS statistic was used
and Neural, the model generated
by the NNET procedure,
was chosen as the best
model of the four.
This is the model that will be
exported by the node including
its score code to be used
downstream in the process flow.
The SAS Viya Output
Report contains
the HTML output produced
by the procedures that ran.
To see the custom report that we
requested using the %em_report
macro, select View, and then
select SAS Viya Reports.
Select Variable
Importance Forest
to display the
variable importance
for the forest model.
The final node in
our example flow
shows that you can use the
Model Comparison node to compare
models from native Enterprise
Miner modeling nodes
with models from SAS Viya.
At this point, it doesn't matter
that the models were trained
in separate environments – they
are all represented the same
way for easy model comparison.
The SAS Viya Selection Statistic
specifies the fit statistic
computed by proc
assess that is used
to determine a champion model.
The default is the KS statistic.
For more information about
the SAS Viya Code node,
see these papers.
Thank you for watching.
