BookmarkSubscribeRSS Feed

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

Started ‎07-30-2014 by
Modified ‎01-06-2016 by
Views 2,311


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="" group=HPReg impute;


Here the SAS procedure HPLOGISTIC performs the model training and generates the score code. The score code file, "", 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 "";


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 "" 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 or the SAS customer support website at

Version history
Last update:
‎01-06-2016 01:40 PM
Updated by:



Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started

Article Tags