Using the SAS Model Manager Access Macros

Accessing the Macros

Before you can use the access macros, your SAS program must access the catalog where the macros are located, and load the macros into memory. Here is example code to do this:
/*******************************************/
/* Specify the macro code location         */
/*******************************************/ 

Filename MMAccess catalog "sashelp.modelmgr.accessmacros.source"; 

/*******************************************/
/* Load the Access macros                  */
/*******************************************/

%include MMAccess; 

Identifying SAS Model Manager Model Repository Objects

The access macros use a SAS Model Manager identifier to specify a unique object such as the version or a model, in the SAS Model Manager model repository. The identifier can be in the form of a Universal Unique Identifier (UUID) or a SAS Model Manager path.
  • A UUID is a case sensitive, 36-character string that uniquely identifies the repository object. An example UUID is cca1ab08-0a28-0e97-0051-0e3991080867.
    If you need to find the UUID or the exact SAS Model Manager path for an object, you can look it up in the SAS Model Manager Project Tree. Select the object and then expand System Properties in the Properties view. The UUID and path values are listed there.
  • The format for a SAS Model Manager path is //repositoryID/MMRoot/folder/project/version/Models/model.
    The name of repositoryID is defined during installation. The names of the folder, project, version, and model that follow in the path are user-defined. SAS Model Manager path specifications always use the forward slash character (/) as a separator.
    For example, a version path might look like //MMModelRepository/MMRoot/HomeEquity/HMEQ/2011.
You use the _MM_CId global macro variable to pass a model repository identifier to an access macro. For more information, see _MM_CId.

Identifying Files Used by Access Macros

All SAS Model Manager access macros that accept SAS file references require the file references to point to a single physical file. File references in the form libref.filename must resolve to a single physical file. Specific logical library references in the form libref must resolve to a directory or a folder.
Concatenated library references cannot be used.
Here is a list of libraries to which you must assign a libref in your SAS programs:
  • the directory that contains your model files
  • the directory that contains the training data
  • the directory that contains your input, output, and target data sets
SAS Model Manager macros use the libref SMMMODEL to access model component files, as in this example:
libname smmmodel "c:\myModel\HMEQ\scorecode";
You can define the libref SMMMODEL at the beginning of your SAS program and use it to access model component files in any of the SAS Model Manager access macros that your program executes.
Here is a list of files that you can identify with a fileref in your SAS programs:
  • a catalog fileref to the SAS Model Manager access macro code
  • the source path and filename for a single file to be registered by the %MM_AddModelFile macro
  • the source path and filename for a SAS Enterprise Miner package file to be registered by the %MM_Register macro
  • the destination path and filename for the %MM_GetModelFile macro

Required Tables

Whether you use the SAS Model Manager window or the access macros, SAS Model Manager must know the model input variables, the output variables, and the target variables to register a model. SAS Model Manager uses an XML file to describe each of these types of files. Before you can register a SAS code model, you must create a SAS data sets that represents the input, output, and target variables:
  • The model input table contains the variables that are used as input by the model. During model registration, SAS Model Manager uses this table to create the inputvar.xml file.
  • The model output table is a table whose variables contain the model output values. During model registration, SAS Model Manager uses this table to create the outputvar.xml file.
  • The model target variable table is a table whose one variable is the target variable that is used in the training data. During model registration, SAS Model Manager uses this file to create the targetvar.xml file.
Each of these tables can be a one-row table. The tables' purpose is to define and describe the variables that are used by the model.
You can create each of these tables using the training data that you used to train your model. The following example SAS program uses the training data to create all three tables:
/********************************************************/
/*  Set the location for the model tables               */
/********************************************************/

libname hmeqtabl "c:\myModel\hmeq\tables";

/*********************************************************/
/*  DATA step to create the target variable table.       */
/*  Because there is only one target variable, keep only */
/*  that variable.                                       */
/*********************************************************/

data hmeqtabl.target;
   set hmeqtabl.training(obs=1);
   keep bad;
run;

/*********************************************************/
/*  DATA step to create the input variable table.        */
/*  Keep only the variables used for input by the model. */
/*********************************************************/

data hmeqtabl.invars;
   set hmeqtabl.training (obs=1);
   keep debtinc delinq derog job loan mortdue ninq reason value yoj;
run;

/*********************************************************/
/*  DATA step to create the output variable table.       */
/*  Keep only the variables used for output by the model.*/
/*  Include the score code to get the output variables.  */
/*********************************************************/

data hmeqtabl.outvars;
   set hmeqtabl.training;
   %include "c:\myModel]hmeq]score.sas"
   keep f_bad i_bad p_0 p_1;
run;

Global Macro Variables

Your SAS program and SAS Model Manager use global macro variables to pass information about the server and the SAS Model Manager model repository to the access macros. Some macros set these global macro variables. You can set any of these global macro variables in your SAS program. At the end of each macro execution, the global macro variable _MM_RC is set to a number that indicates either that the macro executed successfully or that there was an error.
Here is a description of the SAS Model Manager global macro variables:
_MM_CId
contains the name of the current SAS Model Manager object identifier. _MM_CId is either the URL or the SAS Model Manager path to the object in the model repository. You can use the %MM_GetURL to obtain a URL for any object in the SAS Model Manager repository.
The %MM_Register macro sets _MM_CId to contain the SAS Model Manager identifier for the registered model. The %MM_AddModelFile macros sets _MM_CId to the SAS Model Manager identifier for the model to which the file was added.
_MM_Password
contains a password for the SAS Model Manager user. If you do not encode the password using the PWENCODE procedure, the password is printed in the SAS log.
_MM_MulticastPort
contains the multicast port number that the Web Infrastructure Platform server listens for SAS Model Manager requests.
Default: 8080
_MM_RC
contains one of the following return codes after processing a SAS Model Manager macro:
_MM_RC
Return Value
Access Macro
Status
0
All OK
1
Macro parameter error
2
Macro parameter processing error
3
Repository login failed
4
Repository operation failed
5
Generic critical Java error
6
Generic DATA step error
_MM_ResourceURL
contains the URL of the Resources folder. the _MM_Resource URL is set by the %MM_GetURL macro when the macro returns a version URL in the _MM_URL global macro variable.
_MM_MulticastAddress
contains the multicast address of the network server where the Web Infrastructure Platform is installed.
Example: %let _MM_MulticastAddress=239.27.18.213
_MM_URL
contains a URL for a SAS Model Manager object. The %MM_GetURL macro returns a URL in the _MM_URL global macro variable.
_MM_User
contains the name of a SAS Model Manager user on the server that is specified by the _MM_MulticastAddress global macro variable.
Default: the value of SAS automatic macro variable &SYSUSERID.

Required Global Macro Variables

When you use the access macros, the macros need to know the following information:
  • how to access the server where the Web Infrastructure Platform is installed
  • a user and password for processing requests to SAS Model Manager
  • the URL or path to the SAS Model Manager repository
Make sure that your SAS program defines values for these macro variables when you use the access macros:
  • _MM_MulticastAddress
  • _MM_MulticastPort
  • _MM_User
  • _MM_Password
To secure the Model Manager user password, encode the password using the PWENCODE procedure and save it in a file on the network. You can then use a fileref to access the password file and a DATA step to assign the password to the _MM_Password global macro variable. For more information, see Encoding SAS Model Manager User Passwords.
For a description of these macro variables as well as their default values, see Global Macro Variables.
Here is a code example that uses the four macro variables to describe how to the access to the server for the Web Infrastructure Platform.
Filename pwfile  “my-network-drive\pwfile”;

%let _MM_MulticastAddress = 239.27.18.213; 
%let _MM_MulticastPort = 8561; 
%let _MM_User = miller; 
data _null_;
   infile pwfile obs=1 length=l; 
   input @;
   input @1 line $varying1024. l; 
   call symput('_MM_Password',substr(line,1,l)); 
run;