We’re smarter together. Learn from this collection of community knowledge and add your expertise.

Tip: The CODE Statement in SAS® Enterprise Miner™ Procedures

by SAS Employee taiphe on ‎07-30-2014 04:01 PM - edited on ‎01-06-2016 01:40 PM by Community Manager (1,285 Views)


This week, we are discussing the CODE statement in some SAS® Enterprise Miner™ procedures.



Consider the following simple example that shows a modeling process from training to scoring.



The following flow diagram contains six nodes:


  • an Input Data Source node that uses the German credit data (sampsio.dmagecr) as the training data  
  • an HP Regression node that uses the SAS high-performance regression model  
  • a Score node to generate SAS score code for the model  
  • a Score Code Export node to export the generated SAS score code  
  • an Input Data Source node that uses the German credit data (sampsio.dmagescr) as the score data  
  • a Save Data node to save the training and scoring results
Figure 1



The data in the node named DMAGESCR have the same attributes as the German credit data, except that the latter contains the target good_bad. The scored data from the Save Data node contain all the attributes from DMAGESCR in addition to the predicted target, I_good_bad.



The score code that is exported from the Score Code Export node can be used to score other data sets.



As a SAS Enterprise Miner user, you can create a model and score a data set very quickly without using the GUI by using the CODE statement in SAS Enterprise Miner procedures.



The following SAS statements create the same HP Regression model as shown in Figure 1:

        proc hplogistic data=sampsio.dmagecr ; 
           class purpose / upcase ;
           model good_bad(order=internal descending ) = purpose age 
                    amount checking coapp depends duration employed existcr 
                    foreign history housing installp job marital other 
                    property resident savings telephon / link=LOGIT ;
           code file="score.sas" group=HPReg impute;


Here the SAS procedure HPLOGISTIC performs the model training and generates the score code. The score code file, "score.sas", is generated by the CODE statement and saved in the default location. You can also specify a path to store the file in a different location. After you have the score code, the scoring process is very simple. For example, the following statements apply the preceding score code to the scoring data sampsio.dmagescr:


        data scoredata;
            set sampsio.dmagescr;
            %include "score.sas";


The scored data set, scoredata, contains a new variable, I_good_bad, which is the prediction of the target good_bad in the original training data.



In this example, the CODE statement plays an important role and the file "score.sas" is the goal of the model training. The CODE statement is available in most of the frequently used SAS high-performance Enterprise Miner procedures. For example, you can find the CODE statement in HPSPLIT, HPLOGISTIC, HPREG, HPPRINCOMP, HPBIN, HPIMPUTE, HPCLUS, HPNEURAL, and HPSVM procedures.



For more information, please see the SAS Enterprise Miner website at http://www.sas.com/en_us/software/analytics/enterprise-miner.html or the SAS customer support website at http://support.sas.com/software/products/miner

Your turn
Sign In!

Want to write an article? Sign in with your profile.

Looking for the Ask the Expert series? Find it in its new home: communities.sas.com/askexpert.