Linear Regression with PROC REG
Prerequisites: ODS: output delivery and graphs
Linear regression models a numeric outcome as a straight-line function of one or more predictors. Can a student's height predict their weight?
proc reg data=sashelp.class;
model weight = height;
run;
quit;
Output (abridged):
The REG Procedure
Model: MODEL1
Dependent Variable: Weight
Analysis of Variance
Sum of Mean
Source DF Squares Square F Value Pr > F
Model 1 7193.24912 7193.24912 57.08 <.0001
Error 17 2142.48772 126.02869
Corrected Total 18 9335.73684
Root MSE 11.22625 R-Square 0.7705
Dependent Mean 100.02632 Adj R-Sq 0.7570
Coeff Var 11.22330
Parameter Estimates
Parameter Standard
Variable DF Estimate Error t Value Pr > |t|
Intercept 1 -143.02692 32.27459 -4.43 0.0004
Height 1 3.89903 0.51609 7.55 <.0001
How to read it:
- The fitted line:
weight = -143.03 + 3.899 × height. Each extra inch of height goes with about 3.9 more pounds. - Pr > |t| for
Heightis below 0.0001: the slope is clearly not zero. - R-Square 0.7705: height explains about 77% of the variation in weight.
- Root MSE 11.2: the typical prediction error, in pounds.
- The intercept (a student of height 0) has no real-world meaning here — it just positions the line.
PROC REG is interactive: it keeps running so you can add more
MODEL statements, which is why it ends with QUIT;.
Predictions and residuals
proc reg data=sashelp.class noprint;
model weight = height;
output out=fitted p=predicted r=residual;
run;
quit;
proc print data=fitted(obs=3) noobs;
var name height weight predicted residual;
format predicted residual 8.2;
run;
Name Height Weight predicted residual
Alfred 69.0 112.5 126.01 -13.51
Alice 56.5 84.0 77.27 6.73
Barbara 65.3 98.0 111.58 -13.58
More than one predictor
proc reg data=sashelp.class;
model weight = height age / vif;
run;
quit;
- Each estimate is now the effect of that predictor holding the others constant.
/ vifreports variance inflation factors — large values warn that predictors are strongly correlated with each other./ selection=stepwiseand similar options do variable selection; use them with care.
Checking the assumptions
With ODS Graphics on, PROC REG draws a diagnostics panel: residuals
versus predicted values (look for no pattern), a Q-Q plot of residuals
(look for a straight line), and influence measures such as Cook's D.
Always look at it before trusting the p-values.
For categorical predictors, use PROC GLM (next lesson), which has a
CLASS statement; PROC REG needs numeric predictors only.