REGSELECT Procedure
Getting Started: REGSELECT Procedure
Note: Input data must be in a CAS table that is accessible in your CAS session. You must refer to this table by using a two-level name. The first level must be a CAS engine libref, and the second level must be the table name. For more information, see the sections Using CAS Sessions and CAS Engine Librefs and Loading a SAS Data Set onto a CAS Server in Chapter 2, Shared Concepts.
(View the complete code for this example.)
The following example is closely modeled on the example in the section "Getting Started: GLMSELECT Procedure" in the SAS/STAT User's Guide.
The Sashelp.Baseball data set contains salary and performance information for Major League Baseball players who played at least one game in both the 1986 and 1987 seasons, excluding pitchers. The salaries (Time Inc. 1987) are from the 1987 season, and the performance measures are from 1986 (Collier Books 1987). The following step displays (in Figure 1) the variables in the data set:
proc contents varnum data=sashelp.baseball;
ods select position;
run;
Suppose you want to investigate whether you can model the players’ salaries from the 1987 season based on performance measures for the previous season. The aim is to obtain a parsimonious model that does not overfit these particular data, making the model useful for prediction. This example shows how you can use PROC REGSELECT as a starting point for such an analysis. Because the variation of salaries is much greater for the higher salaries, it is appropriate to apply a log transformation to the salaries before you do the model selection.
You can load the Sashelp.Baseball data set into your CAS session by specifying your CAS engine libref in the first statement in the following DATA step:
data mylib.baseball;
set sashelp.baseball;
run;
These statements assume that your CAS engine libref is named mylib, as in the section Using CAS Sessions and CAS Engine Librefs, but you can substitute any appropriately defined CAS engine libref.
Figure 1: Sashelp.Baseball Data Set
| Variables in Creation Order | ||||
|---|---|---|---|---|
| # | Variable | Type | Len | Label |
| 1 | Name | Char | 18 | Player's Name |
| 2 | Team | Char | 14 | Team at the End of 1986 |
| 3 | nAtBat | Num | 8 | Times at Bat in 1986 |
| 4 | nHits | Num | 8 | Hits in 1986 |
| 5 | nHome | Num | 8 | Home Runs in 1986 |
| 6 | nRuns | Num | 8 | Runs in 1986 |
| 7 | nRBI | Num | 8 | RBIs in 1986 |
| 8 | nBB | Num | 8 | Walks in 1986 |
| 9 | YrMajor | Num | 8 | Years in the Major Leagues |
| 10 | CrAtBat | Num | 8 | Career Times at Bat |
| 11 | CrHits | Num | 8 | Career Hits |
| 12 | CrHome | Num | 8 | Career Home Runs |
| 13 | CrRuns | Num | 8 | Career Runs |
| 14 | CrRbi | Num | 8 | Career RBIs |
| 15 | CrBB | Num | 8 | Career Walks |
| 16 | League | Char | 8 | League at the End of 1986 |
| 17 | Division | Char | 8 | Division at the End of 1986 |
| 18 | Position | Char | 8 | Position(s) in 1986 |
| 19 | nOuts | Num | 8 | Put Outs in 1986 |
| 20 | nAssts | Num | 8 | Assists in 1986 |
| 21 | nError | Num | 8 | Errors in 1986 |
| 22 | Salary | Num | 8 | 1987 Salary in $ Thousands |
| 23 | Div | Char | 16 | League and Division |
| 24 | logSalary | Num | 8 | Log Salary |
The following statements select a model by using the default settings for stepwise selection. ODS Graphics must be enabled before you can request plots. For more information about ODS Graphics, see the section ODS Graphics.
ods graphics on;
proc regselect data=mylib.baseball;
class league division;
model logSalary = nAtBat nHits nHome nRuns nRBI nBB
yrMajor crAtBat crHits crHome crRuns crRbi
crBB league division nOuts nAssts nError;
selection method=stepwise plots=all;
run;
The output and graphics from this analysis are presented in Figure 2 through Figure 6.
Figure 2: Selection Information, Number of Observations, Class Level Information, and Dimensions
| Selection Information | |
|---|---|
| Selection Method | Stepwise |
| Select Criterion | SBC |
| Stop Criterion | SBC |
| Effect Hierarchy Enforced | None |
| Stop Horizon | 3 |
| Number of Observations Read | 322 |
|---|---|
| Number of Observations Used | 263 |
| Class Level Information | ||
|---|---|---|
| Class | Levels | Values |
| League | 2 | American National |
| Division | 2 | East West |
| Dimensions | |
|---|---|
| Number of Effects | 19 |
| Number of Parameters | 21 |
The "Selection Information" table provides details about the method and criteria used to perform the model selection. The requested selection method is a variant of the traditional stepwise selection in which the decisions about what effects to add or drop at any step and when to terminate the selection are both based on the Schwarz Bayesian information criterion (SBC). The effect in the current model whose removal yields the maximal decrease in the SBC value is dropped, provided that this lowers the SBC value. When no further decrease in the SBC value can be obtained by dropping an effect in the model, the effect whose addition to the model yields the lowest SBC value is added and the whole process is repeated. The method terminates when dropping or adding any effect increases the SBC value.
Figure 2 displays the "Number of Observations," "Class Level Information," and "Dimensions" tables. The "Number of Observations" table shows that of the 322 observations in the input data, only 263 observations are used in the analysis because there are observations that contain incomplete data. The "Class Level Information" table lists the levels of the classification variables division and league. When you specify effects that contain classification variables, the number of parameters is usually larger than the number of effects. The "Dimensions" table shows the number of effects and the number of parameters that are considered.
The "Stepwise Selection Summary" table in Figure 3 shows the effect that was added or dropped at each step of the selection process together with fit statistics for the model at each step. In this case, both selection and stopping are based on the SBC.
Figure 4 displays the "Stop Reason," "Selection Reason," and "Selected Effects" tables. Note that these tables are displayed without any titles. The "Stop Reason" table indicates that selection stopped because adding or removing any effect would worsen the SBC value that is used as the selection criterion. In this case, because no CHOOSE= criterion is specified in the SELECTION statement, the final model is the selected model; this is indicated in the "Selection Reason" table. The "Selected Effects" table lists the effects in the selected model.
Figure 3: Selection Summary Table
| Selection Summary | ||||
|---|---|---|---|---|
| Step | Effect Entered | Effect Removed | Number Effects In | SBC |
| 0 | Intercept | 1 | -57.2041 | |
| 1 | CrRuns | 2 | -194.3166 | |
| 2 | nHits | 3 | -252.5794 | |
| 3 | YrMajor | 4 | -262.7322 | |
| 4 | CrRuns | 3 | -262.8353 | |
| 5 | nBB | 4 | -269.7804* | |
| * Optimal Value Of Criterion | ||||
Figure 4: Stopping and Selection Reasons
| Stepwise selection stopped because adding or removing an effect does not improve the SBC criterion. |
| The model at step 5 is selected. |
| Selected Effects: | Intercept nHits nBB YrMajor |
|---|
The coefficient panel in Figure 5 enables you to visualize the selection process. In this plot, standardized coefficients of all the effects that are selected at some step of the stepwise method are plotted as a function of the step number. This enables you to assess the relative importance of the effects that are selected at any step of the selection process and to know when effects entered the model. The lower plot in the panel shows how the criterion that is used to choose the selected model changes as effects enter or leave the model.
Figure 5: Coefficient Progression

The criterion panel in Figure 6 provides a graphical view of the progression of the fit criteria as the selection process evolves.
Figure 6: Criterion Panel

The "Analysis of Variance," "Fit Statistics," and "Parameter Estimates" tables shown in Figure 7 display details of the selected model.
Figure 7: Details of the Selected Model
| Analysis of Variance | |||||
|---|---|---|---|---|---|
| Source | DF | Sum of Squares | Mean Square | F Value | Pr > F |
| Model | 3 | 120.52553 | 40.17518 | 120.12 | <.0001 |
| Error | 259 | 86.62820 | 0.33447 | ||
| Corrected Total | 262 | 207.15373 | |||
| Root MSE | 0.57834 |
|---|---|
| R-Square | 0.58182 |
| Adj R-Sq | 0.57697 |
| AIC | -19.06903 |
| AICC | -18.83557 |
| SBC | -269.78041 |
| ASE | 0.32938 |
| Parameter Estimates | |||||
|---|---|---|---|---|---|
| Parameter | DF | Estimate | Standard Error | t Value | Pr > |t| |
| Intercept | 1 | 4.013911 | 0.111290 | 36.07 | <.0001 |
| nHits | 1 | 0.007929 | 0.000994 | 7.98 | <.0001 |
| nBB | 1 | 0.007280 | 0.002049 | 3.55 | 0.0005 |
| YrMajor | 1 | 0.100663 | 0.007551 | 13.33 | <.0001 |
Finally, a table is displayed that shows the amount of time (in seconds) that PROC REGSELECT required to perform the different tasks in the analysis.
Figure 8: Procedure Timing
| Task Timing | ||
|---|---|---|
| Task | Seconds | Percent |
| Setup and Parsing | 0.03 | 48.84% |
| Levelization | 0.02 | 32.62% |
| Model Initialization | 0.00 | 3.51% |
| SSCP Computation | 0.01 | 8.02% |
| Model Selection | 0.00 | 3.65% |
| Cleanup | 0.00 | 2.49% |
| Total | 0.06 | 100.00% |
You might want to examine regression diagnostics for the selected model to investigate whether collinearity among the selected parameters or the presence of outlying or high-leverage observations might be affecting the fit. The following statements include some options and statements to obtain these diagnostics:
proc regselect data=mylib.baseball;
class league division;
model logSalary = nAtBat nHits nHome nRuns nRBI nBB
yrMajor crAtBat crHits crHome crRuns crRbi
crBB league division nOuts nAssts nError / vif clb;
selection method=stepwise;
output out=mylib.baseballOut
p=predictedLogSalary r h cookd rstudent copyvars=(name);
run;
The VIF and CLB options in the MODEL statement request variance inflation factors and 95% confidence limits, respectively, for the parameter estimates. Figure 9 shows the "Parameter Estimates" table, which displays these requested statistics. The variance inflation factors (VIF) measure the inflation in the variances of the parameter estimates due to collinearities that exist among the regressor (independent) variables. Although there are no formal criteria for deciding whether a VIF is large enough to affect the predicted values, the VIF values for the selected effects in this example are small enough to indicate that there are no collinearity issues among the selected regressors.
Figure 9: Parameter Estimates with Additional Statistics
| Parameter Estimates | ||||||||
|---|---|---|---|---|---|---|---|---|
| Parameter | DF | Estimate | Standard Error | t Value | Pr > |t| | Variance Inflation | 95% Confidence Limits | |
| Intercept | 1 | 4.013911 | 0.111290 | 36.07 | <.0001 | 0 | 3.79476 | 4.23306 |
| nHits | 1 | 0.007929 | 0.000994 | 7.98 | <.0001 | 1.49642 | 0.00597 | 0.00989 |
| nBB | 1 | 0.007280 | 0.002049 | 3.55 | 0.0005 | 1.52109 | 0.00325 | 0.01131 |
| YrMajor | 1 | 0.100663 | 0.007551 | 13.33 | <.0001 | 1.02488 | 0.08579 | 0.11553 |
By default, SAS Viya statistical procedures do not include all variables from the input data table in output data tables. The COPYVARS= option in the OUTPUT statement specifies that the variable name in the input data table be added as an identification variable in the baseballOut data table that is produced by the OUTPUT statement. In addition to this variable, the OUTPUT statement requests that predicted values, raw residuals, leverage values, Cook’s D statistics, and studentized residuals be added to the output data table. Note that default names are used for these statistics, except for the predicted values for which a specified name, predictedLogSalary, is supplied. The following statements use PROC PRINT to display five observations in this output data table:
proc print data=mylib.baseballOut(obs=5);
run;
Figure 10: First 5 Observations of the baseballOut Data Set
| Obs | predictedLogSalary | Residual | COOKD | H | RSTUDENT | Name |
|---|---|---|---|---|---|---|
| 1 | 4.73980 | . | . | 0.016087 | . | Allanson, Andy |
| 2 | 6.50852 | -0.29392 | .000730178 | 0.011060 | -0.51031 | Dawson, Andre |
| 3 | 4.66148 | -0.41299 | .002516874 | 0.018999 | -0.72031 | Newman, Al |
| 4 | 6.52518 | 0.47788 | .003069150 | 0.017361 | 0.83308 | Thornton, Andre |
| 5 | 5.65468 | 0.65524 | .002020832 | 0.006219 | 1.13715 | Van Slyke, Andy |