The TREESPLIT Procedure
Example 21.2 Creating a Regression Tree
This example performs an analysis in which a linear regression model is fit. You can alternatively fit a regression tree to predict the salaries of Major League Baseball players based on their performance measures from the previous season by using almost identical code. Regression trees are piecewise constant models that, for relatively small data tables such as Sashelp.Baseball, provide succinct summaries of how the predictor variables determine the predictions. These models are usually easier to interpret than linear regression models. The Sashelp.Baseball data table contains salary and performance information for Major League Baseball players (excluding pitchers) who played at least one game in both the 1986 and 1987 seasons (Time Inc. 1987). You can load the Sashelp.Baseball data set into your CAS session by naming your CAS engine libref in the first statement of the following DATA step:
data mycas.baseball; set sashelp.baseball; run;
The following statements create a regression tree model:
ods graphics on;
proc treesplit data=mycas.baseball maxdepth=3;
class league division;
model logSalary = nAtBat nHits nHome nRuns nRBI nBB
yrMajor crAtBat crHits crHome crRuns crRbi
crBB league division nOuts nAssts nError;
output out=mycas.treesplout;
prune none;
run;
Because no GROW statement is specified, the tree is grown using the RSS criterion by default. Because no PRUNE statement is included, no pruning is performed. The OUTPUT statement requests generation of the data table mycas.treesplout, which contains the predicted salary from the tree model for each observation.
Much of the output for a regression tree is identical to the output for a classification tree. Where there are differences, tables and plots are displayed and discussed on the following pages.
Output 21.2.1 displays the full regression tree.
Output 21.2.1: Overview Diagram of Regression Tree

The final selected tree has eight leaves. In a regression tree, the shade of the leaves represents the predicted response value, which is the average observed logSalary for the observations in that leaf. Node E has the lowest predicted response value, indicated by the lightest shade of blue, and node 7 has the highest, indicated by the dark shade.
Output 21.2.2 shows details of the first three levels of the tree, including the root node.
Output 21.2.2: Detailed Diagram of Regression Tree

As in Output 21.1.3, this diagram displays split variables and split values for the nodes, along with the exact predicted response value, which is the average observed response, in each node.
Output 21.2.3 displays the fit statistic for the final regression tree (the only fit statistic provided for a regression tree is the ASE).
Output 21.2.3: Regression Tree Performance
Output 21.2.4 is a partial display of the mycas.treesplout data table that is created when you specify the OUTPUT statement.
Output 21.2.4: Scored Predictor Data Table
| Obs | P_logSalary | _DT_PredStd_ | _LeafID_ | _Residual_ |
|---|---|---|---|---|
| 1 | 4.6555457426 | 0.3064936468 | 14 | . |
| 2 | 6.8573201516 | 0.4410266912 | 7 | 0.6427120531 |
| 3 | 4.6555457426 | 0.3064936468 | 14 | 0.4070505006 |
| 4 | 6.8573201516 | 0.4410266912 | 7 | -0.145745307 |
| 5 | 5.7477251685 | 0.3269101703 | 11 | -0.56219311 |
| 6 | 4.6555457426 | 0.3064936468 | 14 | . |
| 7 | 6.8573201516 | 0.4410266912 | 7 | . |
| 8 | 4.6555457426 | 0.3064936468 | 14 | -0.089386386 |
| 9 | 6.8573201516 | 0.4410266912 | 7 | 0.2023084645 |
| 10 | 6.35986721 | 0.5351772705 | 8 | -0.260205997 |
The variable P_logSalary contains the predicted salaries on the log scale. Note that all observations in the same leaf have the same predicted response. The OUT= data table can contain additional variables from the DATA= data table if you specify them by using the COPYVARS= option.