Table of Contents
R-squared is a statistical measure that indicates the proportion of variability in a dependent variable that can be explained by the independent variables in a regression model. In SAS, R-squared can be calculated by using the PROC REG procedure, which allows for the creation of regression models. By specifying the “rsquare” option in the MODEL statement, SAS will automatically compute the R-squared value and display it in the output. This value can then be used to evaluate the strength of the relationship between the dependent and independent variables in the model. Additionally, SAS also provides options for calculating adjusted R-squared, which takes into account the number of variables in the model and can provide a more accurate measure of the model’s predictive power. Overall, SAS offers a reliable and efficient way to calculate R-squared and assess the effectiveness of regression models in explaining the variability in a given dataset.
Calculate R-Squared in SAS
R-squared, often written as r2, is a measure of how well a fits a dataset.
This value represents the proportion of the variance in the that can be explained by the predictor variable.
The value for r2 can range from 0 to 1:
- A value of 0 indicates that the response variable cannot be explained by the predictor variable at all.
- A value of 1 indicates that the response variable can be perfectly explained without error by the predictor variable.
The following step-by-step example shows how to calculate the R-squared value for a simple linear regression model in SAS.
Step 1: Create the Data
For this example, we’ll create a dataset that contains the total hours studied and final exam score for 15 students.
We’ll to fit a simple linear regression model using hours as the predictor variable and score as the response variable.
The following code shows how to create this dataset in SAS:
/*create dataset*/ data exam_data; input hours score; datalines; 1 64 2 66 4 76 5 73 5 74 6 81 6 83 7 82 8 80 10 88 11 84 11 82 12 91 12 93 14 89 ; run; /*view dataset*/ proc printdata=exam_data;

Step 2: Fit the Simple Linear Regression Model
Next, we’ll use proc reg to fit the simple linear regression model:
/*fit simple linear regression model*/ proc regdata=exam_data; model score = hours; run;

Notice that the R-squared value in the output is 0.8310.
Step 3: Extract R-Squared Value of Regression Model
If you only want to view the R-squared value of this model and none of the other output results, you can use the following code:
/*fit simple linear regression model*/ proc regdata=exam_data outest=outest noprint; model score = hours / rsquare; run; quit; /*print R-squared value of model*/ proc printdata=outest; var _RSQ_; run;

Notice that only the R-squared value of 0.83098 is shown in the output.
Note: The argument noprint in proc reg tells SAS not to print the entire output of regression results as it did in the previous step.
The following tutorials explain how to perform other common tasks in SAS:
Cite this article
stats writer (2024). How can I calculate R-squared in SAS?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-calculate-r-squared-in-sas/
stats writer. "How can I calculate R-squared in SAS?." PSYCHOLOGICAL SCALES, 24 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-i-calculate-r-squared-in-sas/.
stats writer. "How can I calculate R-squared in SAS?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-calculate-r-squared-in-sas/.
stats writer (2024) 'How can I calculate R-squared in SAS?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-calculate-r-squared-in-sas/.
[1] stats writer, "How can I calculate R-squared in SAS?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.
stats writer. How can I calculate R-squared in SAS?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
