The forestCode action generates SAS DATA step scoring code from a trained forest model. This code can be used to score new data directly within SAS or derived environments. The action provides options to control the generated code's format, select a specific voting method (majority or probability), and limit the number of trees used for scoring, allowing for model simplification or optimization.
| Parameter | Description |
|---|---|
| modelTable | Specifies the in-memory table that contains the trained forest model. This is a required parameter. |
| code | Specifies parameters for the output code generation, including the output table name (casOut) and formatting options like indentation (indentSize) and line width (lineSize). |
| nTree | Specifies the number of trees to use for scoring. If not specified, all trees in the model are used. |
| vote | Specifies the voting strategy for classification: 'MAJORITY' (default) uses the majority class, while 'PROB' uses the average probability. |
| encodeName | If set to True, encodes the predicted variable names (e.g., using P_Target instead of _DT_P_Target) in the generated code. |
Load the 'Cars' dataset and train a forest model to predict the 'Origin' of the car. This model table is required for the forestCode action.
| 1 | PROC CAS; |
| 2 | /* Load sample data */ |
| 3 | TABLE.loadTable / path="cars.csv" caslib="samples" casOut={name="cars", replace=true}; |
| 4 | |
| 5 | /* Train a forest model */ |
| 6 | decisionTree.forestTrain / |
| 7 | TABLE={name="cars"} |
| 8 | target="Origin" |
| 9 | inputs={"MSRP", "EngineSize", "Cylinders", "Horsepower", "MPG_City"} |
| 10 | nominals={"Origin"} |
| 11 | casOut={name="cars_model", replace=true}; |
| 12 | RUN; |
Generates the SAS scoring code from the 'cars_model' table and saves it to a table named 'scoring_code'.
| 1 | PROC CAS; |
| 2 | decisionTree.forestCode / |
| 3 | modelTable={name="cars_model"} |
| 4 | code={casOut={name="scoring_code", replace=true}}; |
| 5 | RUN; |
Generates scoring code using probability voting ('PROB'), limiting the model to the first 10 trees, and encoding variable names.
| 1 | PROC CAS; |
| 2 | decisionTree.forestCode / |
| 3 | modelTable={name="cars_model"} |
| 4 | code={ |
| 5 | casOut={name="prob_scoring_code", replace=true}, |
| 6 | noTrim=true, |
| 7 | indentSize=4 |
| 8 | } |
| 9 | nTree=10 |
| 10 | vote="PROB" |
| 11 | encodeName=true; |
| 12 | RUN; |