Import SAS Code Models and R Models Using Local Files

Overview of Importing SAS Code Models

You use the Local Files method to import models that you create using SAS code, but that were not created in or exported from SAS Enterprise Miner, and R models. An example of such a model might be a SAS LOGISTIC procedure model or an R logistic model.
Note: You can import some SAS/STAT models from the SAS Metadata Repository or from a SAS Package (SPK) file. For more information, see Import Models from the SAS Metadata Repository and Import SAS Model Package Files.
To use the Local Files method, you must prepare model component files. Model component files provide the metadata that is used to process a model in SAS Model Manager. The model component files that you prepare are dependent upon the project's model function. You can find the model function in the project property Model Function. The SAS Model Manager model functions for SAS code models are analytical, classification, prediction, segmentation or any. The model functions for R models are analytical, classification, or prediction. For a list of component files by model function, see Model Template Component Files. If you do not have all of the component files when you import the model, you can create them and add them later using the SAS Model Manager Partial Import utility. For more information, see Import Partial Models.
After you have your model component files, you use the Local Files window to import the component files. To open the Local Files window, right-click the Models folder and select Import fromthen selectLocal Files. In the Local Files window, you select a model template and assign values to the template model properties and model files. The following display shows a partial list of model templates that you can select in the Local Files window as well as the properties and files for the Classification model template:
The Local Files Window
Choose a Model Template in the Local Files Window
After you select your model template, you complete the property values in the General and Properties section, as well as enter your component filenames in the Files section.
SAS code models, at a minimum, require a score code component file, and other component files to define the model input and output variables in SAS tables. Prediction and classification models also require a component file to define target variables.
R models, at a minimum, require SAS and R score code component files, a file for the output parameter estimate, and the other component files to define the model input and output variables in SAS tables. Prediction and classification models also require a component file to define target variables.

Model Templates

What Is a Model Template?

Models that you import into SAS Model Manager are associated with a specific model template. A model template has properties and component files that define a type of model. SAS Model Manager processes four types of models: analytical, classification, prediction, and segmentation. You can create your own model template if your model requires files other than those named in the SAS Model Manager templates.
A model template is an XML file that has three sections. The General section names and describes the model template. The Properties section provides properties to name the model algorithm, the modeler, and a model label. The Files section contains the component files that can be used in the template for that model function type.
You associate your component file with the appropriate model template component file. You do this by dragging a component filename from a tree view to the corresponding SAS Model Manager filename. For example, most templates have a modelinput.sas7bdat component file. In the Local Files window, navigate to the location of model component files, drag your myModelInput.sas7bdat file to the Files section, and drop it as the value for modelinput.sas7bdat. Here is the local file model template component myModelInput.sas7bdat as the value for the modelinput.sas7bdat component file:
Assigning a Model Component File In the Model Template
Your component file filenames do not need to be the same name as the filenames in the model template.
For information about component files for the different model types, see Model Template Component Files.

SAS Model Manager Model Templates

SAS Model Manager provides model templates for analytical, classification, prediction, and segmentation models.
Model Type
Description
Analytical
The Analytical model template is the most generic SAS Model Manager template that is designed for models whose model function does not fall in the prediction, classification, and segmentation category.
Classification
You use the Classification model template if your model is a prediction model that has a categorical, ordinal, or binary target, or if your model is a LOGISTIC procedure regression model. Examples of classification models are models that might classify a loan applicant as Approved or Not Approved, or models that might assess a potential customer's risk of default as Low, Medium, or High.
Prediction
The Prediction model template is used for predictive models. Predictive models declare in advance the outcome of an interval target. A model that assigns a numeric credit score to an applicant is an example of a prediction model.
Segmentation
The Segmentation model template is used for segmentation or cluster models that are written in SAS code. Segmentation models are unsupervised models that have no target variable. A segmentation or cluster model is designed to identify and form segments, or clusters, of individuals or observations that share some affinity for an attribute of interest. The output from a segmentation model is a set of cluster IDs. R models cannot have segmentation model function.
Any
Specify Any when you import a SAS code model and you want a choice of the model template to use in the Local Files window. When you specify Any, SAS Model Manager lists the available model templates in the Choose a model template list in the Local Files window.
If you do not have the required component files that are in the model template, you can add them later, using the SAS Model Manager feature, Import Partial Models.

User Model Templates

Model templates provide users with a way to define metadata about their own model. Most users do not need to write model templates because SAS Model Manager delivers a list of model templates that handle SAS Enterprise Miner models as well as analytical, prediction, classification, and segmentation models. Users can write their own model templates if the model templates that are provided by SAS Model Manager do not satisfy their requirements.
Users can create model templates by using the SAS Model Manager Template Editor. For more information, see Creating a New Model Template.
You can view the user model template files (as well as all of the other SAS Model Manager template files) in the Browse window of the SAS Model Manager Template Editor:
  1. Select Toolsthen selectManage Templates. The SAS Model Manager Template Editor appears.
  2. Select Filethen selectBrowsethen selectBrowse Templates. The Browse Templates window appears.
    Browse Templates window
    Note: The Reserved column indicates whether the template can be modified. Yes indicates that the template cannot be modified. No indicates that the template can be modified. You use reserved templates as a model to create a customized template. When a reserved template is uploaded to the SAS Content Server, SAS Model Manager creates a new file with the same name and changes the new file’s Reserved value to No.
  3. Select a template and click Open. The template opens in the Template Editor.

Model Template Component Files

Here is a list of the component files that are associated with the SAS Model Manager model templates:
Filename
Analytical
Classification
Prediction
Segmentation
IGN_STATS.csv
check mark
EMPublishScore.sas
check mark
Scorecard_GainsTable.csv
check mark
score.sas
check mark
check mark
check mark
check mark
modelinput.sas7bdat
check mark
check mark
check mark
check mark
modeloutput.sas7bdat
check mark
check mark
check mark
check mark
target.sas7bdat
check mark
check mark
inputvar.xml
check mark
check mark
check mark
check mark
outputvar.xml
check mark
check mark
check mark
check mark
targetvar.xml
check mark
check mark
smmpostcode.sas
check mark
targetvariables.csv
check mark
training.sas
check mark
check mark
check mark
check mark
training.log
check mark
check mark
check mark
check mark
training.lst
check mark
check mark
check mark
check mark
outest.sas7bdat
check mark
check mark
check mark
outmodel.sas7bdat
check mark
check mark
check mark
output.spk
check mark
check mark
check mark
check mark
minintResult.spk
check mark
check mark
check mark
layout.sas
check mark
format.sas7bcat
check mark
check mark
check mark
check mark
dataprep.sas
check mark
check mark
check mark
check mark
batch.sas
check mark
check mark
check mark
pmml.xml
check mark
check mark
check mark
training.r
check mark
check mark
check mark
outmodel.rda
check mark
check mark
check mark
score.r
check mark
check mark
check mark
IGN_STATS.csv
The value of IGN_STAT.csv is the name of a file whose values are separated by commas, and whose values are bin definitions for input variables. This is a component file that is generated by SAS Enterprise Miner for a scorecard model and is not needed for SAS code models.
EMPublishScore.sas
The value of EMPublishScore.sas is the name of a SAS code file that is used to change input variables into bins and is a component of a SAS Enterprise Miner scorecard model. This file is needed to define a performance task. This file is not needed for SAS code models.
Scorecard_GainsTable.csv
This file includes the bin score definitions and is not used in reporting by SAS Model Manager. The file's content can be viewed by users.
score.sas
The value of score.sas is the name of a filename for the SAS score code for the model.
For R models, this file transforms a scoring data set to an R data frame.
modelinput.sas7bdat
The value of modelinput.sas7bdat is the name of a sample data set that is used to create an inputvar.xml file for the model if one does not exist. When no inputvar.xml file exists for the model, SAS Model Manager creates the inputvar.xml file using the variable name and attributes in the modelinput.sas7bdat file. Observation values are not used. Therefore, the sample data set can have no observations or it can have any number of observations. If an inputvar.xml is specified in the model template, modelinput.sas7bdat is ignored.
When you import a SAS code model, the data set that you used to test your score code can be used as the value for the modelinput.sas7bdat file.
modeloutput.sas7bdat
The value of modeloutput.sas7bdat is the name of a sample data set that is used to create an outputvar.xml file for the model if one does not exist. When no outputvar.xml file exists for the model, SAS Model Manager creates the outputvar.xml file using the variable name and attributes in the modeloutput.sas7bdat file. Observation values are not used. Therefore, the sample data set can have no observations or it can have any number of observations. If an outputvar.xml is specified in the model template, modeloutput.sas7bdat is ignored.
You can create a modeloutput.sas7bdat file by running the score.sas file against the modelinput.sas7bdat file.
target.sas7bdat
The value of target.sas7bdat is the name of a sample data set that is used to create a targetvar.xml file for the model if one does not exist. When no targetvar.xml file exists for the model, SAS Model Manager creates the targetvar.xml file using the variable name and attributes in the target.sas7bdat file. Data set values are not used. Therefore, the sample data set can have no observations or it can have any number of observations. If a targetvar.xml file is specified in the model template, target.sas7bdat is ignored.
You can create a target.sas7bdat file by creating a data set that keeps only the target variables that are taken from the training data set, as in this example:
data mydir.target;
    set mydir.myModelTraining (obs-1)
    keep P_BAD;
run;
inputvar.xml
The value of inputvar.xml is the name of an XML file that defines the model input variables. When your model template includes a file for modelinput.sas7bdat, SAS Model Manager creates the model inputvar.xml file. Otherwise, you must create the XML file.
The following XML file is a sample inputvar.xml file that has one variable, CLAGE. You can use this model to create an inputvar.xml file that contains a VARIABLE element for each model input variable.
<?xml version="1.0" encoding="utf-8"?>
<TABLE>
   <VARIABLE>
		 <NAME>CLAGE</NAME>
		 <TYPE>N</TYPE>
		 <LENGTH>8</LENGTH>
		 <LABEL Missing=""/>
		 <FORMAT Missing=""/>
		 <LEVEL>INTERVAL</LEVEL>
		 <ROLE>INPUT</ROLE>
		</VARIABLE>
   </TABLE>
NAME
specifies the variable name.
TYPE
specifies the variable type. Valid values are N for numeric variables and C for character variables.
LENGTH
specifies the length of the variable.
LABEL Missing=""
specifies the character to use for missing values. The default character is a blank space.
FORMAT Missing=""
specifies a SAS format to format the variable.
LEVEL
specify either NOMINAL, ORDINAL, INTERVAL, or BINARY.
ROLE
specify INPUT for input variables.
outputvar.xml
The value of outputvar.xml is the name of an XML file that defines the model output variables. When your model template includes a file for modeloutput.sas7bdat, SAS Model Manager creates the model outputvar.xml file. Otherwise, you must create the XML file.
The following XML file is a sample outputvar.xml file that has one variable, I_BAD. You can use this model to create an outputvar.xml file that contains a VARIABLE element for each model output variable.
<?xml version="1.0" encoding="utf-8"?>
<TABLE>
   <VARIABLE>
		 <NAME>I_BAD</NAME>
		 <TYPE>C</TYPE>
		 <LENGTH>12</LENGTH>
		 <LABEL>Into: BAD</LABEL>
		 <FORMAT Missing=""/>
		 <LEVEL>NOMINAL</LEVEL>
		 <ROLE>CLASSIFICATION</ROLE>
   </VARIABLE>
 </TABLE>
NAME
specifies the variable name.
TYPE
specifies the variable type. Valid values are N for numeric variables and C for character variables.
LENGTH
specifies the length of the variable.
LABEL Missing=""
specifies a label for the output variable.
FORMAT Missing=""
specifies a SAS format to format the variable.
LEVEL
specify either NOMINAL, ORDINAL, INTERVAL, or BINARY.
ROLE
specify the type of model output. Valid values are CLASSIFICATION, PREDICT, SEGMENT, and ASSESS.
targetvar.xml
The value of targetvar.xml is the name of an XML file that defines the model target variables. When your model template includes a file for target.sas7bdat, SAS Model Manager creates the targetvar.xml file. Otherwise, you must create the XML file.
The following XML file is a sample targetvar.xml file that has one variable, I_BAD. You can use this model to create an outputvar.xml file that contains a VARIABLE element for each model output variable.
<?xml version="1.0" encoding="utf-8"?>
<TABLE>
   <VARIABLE>
		 <NAME>BAD</NAME>
		 <TYPE>N</TYPE>
		 <LENGTH>8</LENGTH>
		 <LABEL>Missing=””/>
		 <FORMAT Missing=""/>
		 <LEVEL>BINARY</LEVEL>
		 <ROLE>TARGET</ROLE>
  </VARIABLE>
 </TABLE>
NAME
specifies the variable name.
TYPE
specifies the variable type. Valid values are N for numeric variables and C for character variables.
LENGTH
specifies the length of the variable.
LABEL Missing=""
specifies a label for the target variable.
FORMAT Missing=""
specifies a SAS format to format the variable.
LEVEL
specify either NOMINAL, ORDINAL, INTERVAL, or BINARY.
ROLE
specify TARGET.
smmpostcode.sas
SAS Model Manager creates this file to document the mapping that the user specified between the model variables and the project variables.
training.sas
This file is the optional SAS code that was used to train the model that you are importing. If at some time, SAS Model Manager reporting utilities detect a shift in the distribution of model input data values or a drift in the model's predictive capabilities, the training.sas code can be used to retrain the model on the newer data. If it is not available at import time, the training.sas code can be added at a later point using the SAS Model Manager Partial Import utility.
training.log
This file is the optional log file that was produced when the model that you are importing was trained. The information in the optional SAS training log can be helpful if the model must be retrained in the future.
trainingvariables.csv
This optional file contains a list of the training variables.
training.lst
This file is the optional text output that is produced when the training.sas code is run. The information in the optional SAS training.lst table can be helpful if the model must be retrained in the future.
outest.sas7bdat
This data set contains output estimate parameters that are produced by a few SAS procedures, including the LOGISTIC procedure.
outmodel.sas7bdat
This data set contains output data that is produced by a few SAS procedures, including the LOGISTIC procedure and the ARBORETUM procedure. It contains complete information for later scoring by the same SAS procedure using the SCORE statement.
output.spk
This file is the SAS package file that contains the SPK collection of model component files.
miningresult.spk
This is a SAS package file that stores detailed information about SAS Enterprise Miner nodes in the flow from which the model is created and the detailed information for SAS/STAT item store models.
layout.xml
This optional file contains information about the SAS Enterprise Miner diagram topology.
format.sas7bcat
This file is the optional SAS formats catalog file that contains the user-defined formats for their training data. If the model that you are importing does not use a user-defined format, then you do not need to import a format.sas7bcat catalog file.
dataprep.sas
This file contains optional SAS code that is intended to be executed before each run of score code.
batch.sas
This file is created by SAS Enterprise Miner and is used for model retraining by SAS Model Manager.
pmml.xml
This file contains score code in PMML format.
training.r
This is an optional R script file that is used to retrain R models in SAS Model Manager.
outmodel.rda
SAS Model Manager requires this file to save the output parameter estimate for R models.
score.r
This file is an R script that is used to predict new data.
For information about preparing R model component files, see SAS Model Manager R Model Support.

Viewing Model Template Files

You can view model template files using the Browse Templates window. You open the Browse Templates window from the SAS Model Manager Template Editor
  1. From the SAS Model Manager window, select Toolsthen selectManage Templates.
  2. From the SAS Model Manager Template Editor, select Filethen selectBrowsethen selectBrowse Templates.
  3. In the Browse Templates window, select the template.
  4. Click Open. The template opens in the SAS Model Manager Template Editor.
Reserved templates cannot be modified.

Importing a SAS Code Model

To import a SAS code model, follow these steps:
  1. Copy your SAS code model and all of the associated metadata files to a location on your local workstation.
  2. In the Project Tree, navigate to the project's version.
    MMRootthen selectorganizational folderthen selectproject folderthen selectversion folder
  3. Right-click the Models folder and select Import Fromthen selectLocal Files.
    The Local Files Window
  4. Use the file utility icons to navigate to the folder that contains the component files for your model.
  5. Select a template from the Choose a model template list. For more information about the type of model templates, see Model Templates.
  6. Enter a text value in the model Name field.
  7. Complete the template fields. Drag the files from the left of the window to the corresponding file property on the right.
    The Local Files Window
    Note: The filenames do not have to match, provided that the file contents meets the file property requirements. For more information, see the following topics:
  8. Click OK. After the SAS Model Manager processes the model import request, the new model appears in the Models folder of your project's version.

Importing an R Model

For information about preparing R model files, see SAS Model Manager R Model Support.
Before you import a model into your project's version, verify that the model type matches the Model Function property setting on the Project Properties panel. For more information about model functions, see Specific Properties for a Project.
To import an R model into SAS Model Manager, follow these steps:
  1. In the Project Tree, navigate to the project's version.
    MMRootthen selectorganizational folderthen selectproject folderthen selectversion folder
  2. Right-click the Models folder and select Import fromthen selectLocal Files.
  3. In the Local Files window, select the R model template in the Choose a model template box.
  4. Enter R model-type in the Name field (for example, R Logistic).
  5. Expand Desktop and navigate to the location of the R model files. Complete these required model properties:
    1. Drag the model input table to the modelinput.sas7bdat property.
    2. Drag the model output table to the modeloutput.sas7bdat property.
    3. Drag the target table to the target.sas7bdat property.
    4. Drag the model.rda file to the outmodel.sas7bdat property.
    5. Drag the R script file for scoring to the score.r property.
    6. Drag the SAS scoring program to the score.sas property.
  6. If you have other component files, drag them to their respective properties.
  7. Click OK. After SAS Model Manager processes the model import request, the new model appears in the Models folder of your project's version.
  8. Repeat steps 2 through 7 to import additional R files from your client computer folder.