Multiple linear regression is a method we can use to understand the relationship between two or more predictor variables and a response variable.
This tutorial explains how to perform multiple linear regression in SAS.
Step 1: Create the Data
Suppose we want to fit a multiple linear regression model that uses number of hours spent studying and number of prep exams taken to predict the final exam score of students:
Exam Score = β0 + β1(hours) +β2(prep exams)
First, we’ll use the following code to create a dataset that contains this information for 20 students:
/*create dataset*/ data exam_data; input hours prep_exams score; datalines; 1 1 76 2 3 78 2 3 85 4 5 88 2 2 72 1 2 69 5 1 94 4 1 94 2 0 88 4 3 92 4 4 90 3 3 75 6 2 96 5 4 90 3 4 82 4 4 85 6 5 99 2 1 83 1 0 62 2 1 76 ; run;
Step 2: Perform Multiple Linear Regression
Next, we’ll use proc reg to fit a multiple linear regression model to the data:
/*fit multiple linear regression model*/ proc reg data=exam_data; model score = hours prep_exams; run;

Here is how to interpret the most relevant numbers in each table:
Analysis of Variance Table:
The overall F-value of the regression model is 23.46 and the corresponding p-value is <.0001.
Since this p-value is less than .05, we conclude that the regression model as a whole is statistically significant.
Model Fit Table:
The R-Square value tells us the percentage of variation in the exam scores that can be explained by the number of hours studied and the number of prep exams taken.
In general, the larger the R-squared value of a regression model the better the predictor variables are able to predict the value of the response variable.
In this case, 73.4% of the variation in exam scores can be explained by the number of hours studied and number of prep exams taken.
The Root MSE value is also useful to know. This represents the average distance that the observed values fall from the regression line.
In this regression model, the observed values fall an average of 5.3657 units from the regression line.
Parameter Estimates Table:
We can use the parameter estimate values in this table to write the fitted regression equation:
Exam score = 67.674 + 5.556*(hours) – .602*(prep_exams)
We can use this equation to find the estimated exam score for a student, based on the number of hours they studied and the number of prep exams they took.
For example, a student that studies for 3 hours and takes 2 prep exams is expected to receive an exam score of 83.1:
Estimated exam score = 67.674 + 5.556*(3) – .602*(2) = 83.1
The p-value for hours (<.0001) is less than .05, which means that it has a statistically significant association with exam score.
However, the p-value for prep exams (.5193) is not less than .05, which means it does not have a statistically significant association with exam score.
We may decide to remove prep exams from the model since it isn’t statistically significant and instead perform simple linear regression using hours studied as the only predictor variable.
Additional Resources
The following tutorials explain how to perform other common tasks in SAS:
How to Calculate Correlation in SAS
How to Perform Simple Linear Regression in SAS
How to Perform a One-Way ANOVA in SAS
Thank you so so much for creating Statology Zach. This has helped me so much in my degree and my career. Much appreciated.
You are very welcome Mamello! We appreciate your support!
Hi Zach,
Can you use multiple regression and GLM in the same analysis? In other words, I have missing values for some subjects and I don;t want the entire subject to be excluded from the analysis. I did this with ANOVA, but how would you adapt it to multiple regression?
Many thanks,
Lori
Yes, you can use both **multiple regression** and **generalized linear models (GLMs)** in the same analysis, depending on the nature of your data and the goals of your study. The issue of missing values can indeed be addressed within these frameworks. Here’s how you could adapt it:
—
### 1. **Multiple Regression with Missing Data**
When dealing with missing data in multiple regression, standard regression models (e.g., Ordinary Least Squares) will exclude rows with any missing values, a method called **listwise deletion**. To avoid this, you can handle missing data through:
#### a. **Imputation**
– Use methods like **mean imputation**, **median imputation**, or **multiple imputation (MI)** to fill in missing values.
– MI is preferable because it considers the uncertainty of missing data, creating several imputed datasets, running the regression on each, and combining the results.
#### b. **Maximum Likelihood Estimation**
– This approach can estimate regression parameters directly by maximizing the likelihood of observed data, considering the missingness pattern.
#### c. **Mixed Models**
– If your data has a hierarchical or nested structure, mixed models (e.g., linear mixed models) can handle missingness by using all available data and estimating parameters based on the data’s covariance structure.
—
### 2. **Generalized Linear Models (GLMs)**
GLMs extend multiple regression to accommodate non-normal response variables (e.g., binary, count, or skewed data). Like multiple regression, GLMs can also handle missing data using similar techniques:
#### a. **Multiple Imputation**
– As with multiple regression, imputing missing values before fitting the GLM can help you retain all subjects.
#### b. **Maximum Likelihood**
– Many GLM frameworks can estimate parameters using all available data without requiring complete cases.
#### c. **Bayesian GLMs**
– Bayesian approaches can explicitly model missing data as part of the analysis, treating them as unknown parameters to estimate.
—
### 3. **Adapting ANOVA Handling of Missing Data to Regression**
In ANOVA, techniques like **Type III sum of squares** or **general linear hypothesis tests** often allow partial data usage. To adapt this to regression:
– Use **GLM packages** (e.g., in R: `glm()`, Python: `statsmodels.glm`) that allow missing data handling.
– Combine regression modeling with imputation strategies to ensure missingness does not result in listwise deletion.
—
### Workflow Example
Suppose you have data for multiple predictors (`X1`, `X2`, …, `Xn`) and a dependent variable (`Y`), but some predictors have missing values.
1. **Inspect the Missing Data**: Assess the pattern of missingness (missing completely at random [MCAR], at random [MAR], or not at random [MNAR]).
2. **Choose a Strategy**:
– For MCAR/MAR: Use **multiple imputation** or **maximum likelihood**.
– For MNAR: Consider advanced models (e.g., selection models or pattern-mixture models).
3. **Apply the Model**:
– Fit a GLM or multiple regression to the complete dataset (after imputation or using methods that handle missing data directly).
4. **Validate**:
– Check the model’s robustness by comparing results across imputed datasets or testing sensitivity to different missing data treatments.
—
### Tools to Help
– **R**:
– `mice` or `Amelia` for multiple imputation.
– `glm` for generalized linear models.
– `lme4` for mixed models.
– **Python**:
– `statsmodels` for GLMs.
– `scikit-learn` for regression and imputation.
By combining the flexibility of GLMs with imputation methods, you can conduct a robust analysis without excluding entire subjects due to missing data.