'Life is after all a recursive summation, indeed     Let's do some Statistics!

Department of Civil and Environmental Engineering
Frank Batten College of Engineering and Technology
Old Dominion University
Norfolk, Virginia 23529-0241, USA
Tel) (757) 683-3753
Fax) (757) 683-5354


	
Return to CEE 700/800 Homepage
CEE 700/800 Access Counter
 
Go back to
SAS Source Page
Multiple Linear Regression
SAS Source: M_REG.SAS

Description

  1. Use following SAS source as a template for your Multiple Linear Regression task
  2. Anything enclosed by "/*and "*/" treated as a comment, and you can put as many comments as you wish.
  3. You can include as many variables as you want into the regression model.
  4. You can also include product term(s) if you suspect interaction between variable(s)

Closely examine comments in the source for specific model options.

SAS Listing


OPTIONS LINESIZE=80;
TITLE1 'Multiple Least-Square Regression Example';
TITLE2 'Multiple variables with interaction terms';
TITLE2 'Dependent Variable, Y: CEMENT MIX';  
TITLE4 'X1, X2, X3, X4 are four ingredients in mix';  
DATA MIX;  
/* Substitute with your variables                */
INPUT Y X1 X2 X3 X4;
/* Product terms based on input variables        */
     X1X2 = X1*X2;        
     X1X3 = X1*X3;
     X1X4 = X1*X4;
/* You can also transform variables using followings   */
/*  LNX    = log(X);        natural logarithm (base e) */ 
/*  L10X   = log10(X);      log to base 10             */ 
/*  PWX    = X**t;          raises 't' to a power,     */
/*                          t could be integer or real */ 
/*  SQRX   = sqrt(X);       square root                */ 
/*  EXPX   = exp(X);        exponential function       */ 
/*  cosX   = cos(X);        cosine function            */ 
/*  sinX   = sin(X);        sine function              */ 
/*  tanX   = tan(X);        tangent function           */ 

/* substitute with your inputs.                  */
/* missing obs. (.) can be also used             */
CARDS;  
 78.5      7      26      6      60
 74.3      1      29     15      52
104.3     11      56      8      47
 87.6     11      31      8      47
 95.9      7      52      6      33
109.2     11      55      9      22
102.7      3      71     17       6
 72.5      1      31     22      44
 93.1      2      54     18      22
115.9     21      47      4      26
 83.8      1      40     23      34
113.3     11      66      9      12
109.4     10      68      8      12
.         10      70      6      14
.         15      75      4      12
;
RUN;

/* Print the original data set                   */
PROC PRINT;
RUN;

/********************************************************/
/* General Linear Model Regression */
/********************************************************/
PROC GLM DATA=MIX;                          
/* P = Calculates predicted values from the      */
/*     input data and the estimated regression   */ 
/*     model                                     */ 
/* CLM = Compute 95% confidence limits for       */
/*     expected values                           */
   MODEL Y= X1 X2 X3 X4 / P CLM;

/* Predicted & Residual                          */
   OUTPUT OUT=A P=YHAT R=RESID;
   TITLE2 'General linear model & related residual plots';  
RUN;

/* Plot results                                  */
PROC PLOT DATA=A;
/* Overlay P & R plots                           */
   PLOT Y*YHAT ="P" RESID *YHAT="R" / OVERLAY;        
RUN;

/********************************************************/
/* Regression procedure                                 */
/* You don't have to run all four selection methods     */
/* Following four methods are for demonstration purpose */
/* If not sure, use STEPWISE selection method           */
/*                                                      */
/* To suppress INTERCEPT term, use 'NOINT option        */
/* example)                                             */
/* MODEL Y=X1 X2 X3 X4 X1X2 X1X3 X1X4/SELECTION=STEPWISE NOINT;*/
/********************************************************/
/* Other frequently used options are;                   */
/*                                                      */
/* SS1 = Sequential sums of squares                     */
/* SS2 = Partial sums of squares                        */
/* STB = Standardized parameter estimates               */
/* CLB = (1-alpha)*100% confidence limits for the       */ 
/*       parameter estimates                            */
/* COVB = Covariance matrix of estimates                */
/* CORRB = Correlation matrix of estimates              */
/********************************************************/

PROC REG DATA =MIX; 
   MODEL Y=X1 X2 X3 X4 X1X2 X1X3 X1X4/ SELECTION =FORWARD; 
   TITLE1 'Forward Regression';
   /* Add one at a time & compare f0 */
RUN;

PROC REG DATA=MIX;  
   MODEL Y=X1 X2 X3 X4 X1X2 X1X3 X1X4 / SELECTION=BACKWARD;
   TITLE1 'Backward Regression';
   /* Remove one at a time & compare f0 */
RUN;

PROC REG DATA=MIX;  
   MODEL Y=X1 X2 X3 X4 X1X2 X1X3 X1X4 / SELECTION=STEPWISE;
   TITLE1 'Stepwise Regression';
   /* Add & substract one at a time & compare f0 */
RUN;

PROC REG DATA=MIX;  
   MODEL Y =X1 X2 X3 X4 X1X2 X1X3 X1X4 / SELECTION=RSQUARE;
   TITLE1 'R-square Regression';
   /* Estimate best reg based on max. r2 */
RUN;

PROC REG DATA=MIX;  
   MODEL Y =X1 X2 X3 X4 X1X2 X1X3 X1X4 / SELECTION=ADJRSQ;
   TITLE1 'Adjusted R-square Regression';
   /* Estimate best reg based on max. Adjusted r2 */
RUN;

PROC REG DATA=MIX;  
   MODEL Y =X1 X2 X3 X4 X1X2 X1X3 X1X4 / SELECTION=CP;
   TITLE1 'Mallows. Cp statistics Regression';
   /* Estimate best reg based on Mallows. Cp statistics */
RUN;

PROC REG DATA=MIX;  
   MODEL Y=X1 X2 X3 X4 X1X2 X1X3 X1X4
       / SELECTION=STEPWISE NOINT
         SS1 SS2 STB CLB COVB CORRB ;
   TITLE1 'Stepwise Regression with No Int. and other Optional Statistics';
RUN;



SAS Listing

Above SAS source can be simplified into a skeleton source for a simple linear least-square regression.


OPTIONS LINESIZE=80;
TITLE1 'Multiple Least-Square Regression Example';
TITLE2 'Multiple variables with interaction terms';
TITLE2 'Dependent Variable, Y: CEMENT MIX';  
TITLE4 'X1, X2, X3, X4 are four ingredients in mix';  
DATA MIX;  
/* Substitute with your variables                */
INPUT Y X1 X2 X3 X4;

/* Product terms based on input variables        */
     X1X2 = X1*X2;        
     X1X3 = X1*X3;
     X1X4 = X1*X4;
CARDS;  
 78.5      7      26      6      60
 74.3      1      29     15      52
104.3     11      56      8      47
 87.6     11      31      8      47
 95.9      7      52      6      33
109.2     11      55      9      22
102.7      3      71     17       6
 72.5      1      31     22      44
 93.1      2      54     18      22
115.9     21      47      4      26
 83.8      1      40     23      34
113.3     11      66      9      12
109.4     10      68      8      12
.         10      70      6      14
.         15      75      4      12
;
RUN;

/********************************************************/
/* Regression procedure                                 */
/* You don't have to run all four selection methods     */
/* Following four methods are for demonstration purpose */
/* If not sure, use STEPWISE selection method           */
/*                                                      */
/* To suppress INTERCEPT term, use 'NOINT option        */
/* example)                                             */
/* MODEL Y=X1 X2 X3 X4 X1X2 X1X3 X1X4/SELECTION=STEPWISE NOINT;*/
/********************************************************/
PROC REG DATA=MIX;  
   MODEL Y=X1 X2 X3 X4 X1X2 X1X3 X1X4/  SELECTION=STEPWISE;
   TITLE1 'Stepwise Regression';
RUN;


SAS User Guide (SUG) for Procedures (PROC) used in the Source

SUG GLM procedure
SUG PLOT procedure
SUG PRINT procedure
SUG REG procedure
Go back to
SAS Source Page

Return to CEE 700/800 Homepage Return to CEE 700/800 Homepage Move to the Top of this page