Risk Modeling and Decisioning Action Set

Scoring New Data by Using the aStore Action Set

This section contains PROC CAS code.

Note: Input data must be accessible in your CAS session, either as a CAS table or as a transient-scope table. A CAS table has a two-level name: the first level is your CAS engine libref, and the second level is the table name. You refer to this table in the CAS procedure by specifying only the second level. For more information about two-level names, see Chapter 2, Shared Concepts (SAS Viya: Machine Learning Procedures). A transient-scope table is called directly from the action and exists in memory for the duration of the action. For more information about accessing data, see SAS Viya: System Programming Guide. For more information about PROC CAS and programming in CASL, see SAS Cloud Analytic Services: CASL Programmer’s Guide and SAS Cloud Analytic Services: CASL Reference.

This example illustrates how you can use the optBinning action to produce an analytic store, and then use the score action from the aStore action set, to score an input data table in SAS Viya. Assume that you already have the input data table mycas.datain and the parameter table mycas.param loaded into your CAS session, as in the section Fit a Credit Scoring Model.

The following statements run the optBinning action and save the scoring model to an analytic store in the mycas.scoremodel table by using the saveState parameter:

proc cas;
   loadactionset "riskmd";

   action optBinning /
      data={name="datain"}
      param={name="parms"}
      adjustFactor=0.2
      savestate={name="scoremodel", replace="TRUE"}
    ;
run;

The following DATA step creates a data set in which each observation contains the customer’s age, cash reserves, and income:

data test;
   input name $ age cash income;
datalines;
a  20   500  2300
b  23  1000  3000
;
run;

Load the data set into a CAS table in your current CAS session as follows:

data mycas.test;
set test;
run;

Then use the score action from the aStore action set as follows to score the input table mycas.test:

proc cas;
   loadactionset "aStore";
   action aStore.score /
      rstore={name="scoremodel"},
      table={name="test"},
      out={name="out", replace="TRUE"},
      copyvars={"name", "age", "cash", "income"}
   ;
run;
quit;

You can see the scoring results shown in Output 34.3.1 by using the PRINT statement:

proc print data=mycas.out;
run;

Output 34.3.1: Scoring Results from the Score File

ObsGRP_AGEWOE_AGEGRP_CASHWOE_CASHGRP_INCOMEWOE_INCOMEnameagecashincome
11-0.309511-0.144092-0.21735a205002300
220.2288020.052322-0.21735b2310003000


In Output 34.3.1, the generated columns GRP_AGE, GRP_CASH, and GRP_INCOME contain the bin numbers for the matching characteristic for each customer. For example, the GRP_AGE column has the bin numbers for the age characteristic. The generated columns WOE_AGE, WOE_CASH, and WOE_INCOME contain the weight of evidence (WOE) values for the matching characteristic for each customer. For example, the WOE_AGE column has the WOE values for the age characteristic.

Scoring New Data by Using the aStore Action Set

This section contains Lua code for the analysis in the CASL version of this example, which contains details about the results.

Note: In order to run this code, the data that are described in the CASL version need to be accessible to the CAS server. One way to do this is to convert the datain data to the comma-separated-value (CSV) file datain.csv, convert the parms data to the CSV file parms.csv, and then use the following code to load the CSV files into CAS:

s:loadtable{casLib="casuser", path="datain.csv"}
s:loadtable{casLib="casuser", path="parms.csv"}

For more information about coding in Lua, see Getting Started with SAS Viya for Lua and SAS Viya: System Programming Guide.

This example illustrates how you can use the optBinning action to produce an analytic store, and then use the score action from the aStore action set to score an input data table in SAS Viya.

Assume that you already have the input data table mycas.datain and the parameter table mycas.param loaded into your CAS session, as in the section Fit a Credit Scoring Model.

The following statements run the optBinning action and save the scoring model to an analytic store in the mycas.scoremodel table by using the saveState parameter:

s:loadactionset{actionset="riskmd"}
s:riskmd_optBinning{
   data={name="datain"},
   param={name="parms"},
   adjustFactor=0.2,
   printLevel=2,
   savestate={name="score", replace="True"}
}

Then you use the score action from the aStore action set as follows to score the input table mycas.test:

s:loadactionset{actionset="aStore"}
s:aStore_score{
   rstore={name="scoremodel"},
   table={name="test"},
   out={name="out", replace="TRUE"},
   copyvars={"name", "age", "cash", "income"}
}

You can see the scoring results from the following statements:

r = s:fetch{table={name="out"}, to=50}
print(r.Fetch)

For details about the results of this analysis, see the CASL version of this example.

Scoring New Data by Using the aStore Action Set

This section contains Python code for the analysis in the CASL version of this example, which contains details about the results.

Note: In order to run this code, the data that are described in the CASL version need to be accessible to the CAS server. One way to do this is to convert the datain data to the comma-separated-value (CSV) file datain.csv, convert the parms data to the CSV file parms.csv, and then use the following code to load the CSV files into CAS:

s.upload_file('datain.csv')
s.upload_file('parms.csv')

For more information about coding in Python, see Getting Started with SAS Viya for Python and SAS Viya: System Programming Guide.

This example illustrates how you can use the optBinning action to produce an analytic store, and then use the score action from the aStore action set to score an input data table in SAS Viya.

Assume that you already have the input data table mycas.datain and the parameter table mycas.param loaded into your CAS session, as in the section Fit a Credit Scoring Model.

The following statements run the optBinning action and save the scoring model to an analytic store in the mycas.scoremodel table by using the saveState parameter:

s.loadactionset(actionset="riskmd")
s.riskmd.optBinning(
    data={"name":"datain"},
    param={"name":"parms"},
    adjustFactor=0.2,
    printLevel=2,
    savestate={"name":"scoremodel", "replace":"True"}
)

Then you use the score action from the aStore action set as follows to score the input table mycas.test:

s.loadactionset(actionset="aStore")
s.score(
   rstore={"name":"scoremodel"},
   table={"name":"test"},
   out={"name":"out", "replace":"True"},
   copyvars={"name", "age", "cash", "income"}
)

You can see the scoring results from the following statements:

print(s.fetch(table={"name":"out"}, to=50))

For details about the results of this analysis, see the CASL version of this example.

Scoring New Data by Using the aStore Action Set

This section contains R code for the analysis in the CASL version of this example, which contains details about the results.

Note: In order to run this code, the data that are described in the CASL version need to be accessible to the CAS server. One way to do this is to convert the datain data to the comma-separated-value (CSV) file datain.csv, convert the parms data to the CSV file parms.csv, and then use the following code to load the CSV files into CAS:

m <- cas.read.csv(s, "datain.csv", casOut=list(name="datain"))
m <- cas.read.csv(s, "parms.csv", casOut=list(name="parms"))

For more information about coding in R, see Getting Started with SAS Viya for R and SAS Viya: System Programming Guide.

This example illustrates how you can use the optBinning action to produce an analytic store, and then use the score action from the aStore action set to score an input data table in SAS Viya.

Assume that you already have the input data table mycas.datain and the parameter table mycas.param loaded into your CAS session, as in the section Fit a Credit Scoring Model.

The following statements run the optBinning action and save the scoring model to an analytic store in the mycas.scoremodel table by using the saveState parameter:

loadActionSet(s,'riskmd')
m <- cas.riskmd.optBinning(s,
                    data =list(name="datain"),
                    param =list(name="parms"),
                    adjustFactor=0.2,
                    printLevel=2,
                    savestate=list(name="scoremodel", replace="TRUE")
                    )

Then you use the score action from the aStore action set as follows to score the input table mycas.test:

loadActionSet(s,'aStore')
m <- cas.aStore.score(s,
                    rstore=list(name="scoremodel"),
                    table =list(name="test"),
                    out   =list(name="out", replace="TRUE"),
                    copyvars=list("name", "age", "cash", "income")
                    )

You can see the scoring results from the following statements:

output <- cas.table.fetch(s, table = list(name = "out"), to = 50)
print(output)

For details about the results of this analysis, see the CASL version of this example.

Last updated: August 04, 2026