Table of Contents
To create a scatterplot with a regression line in SAS, you can use the PROC SGPLOT procedure. First, you will need to load your data into SAS and specify the variables you want to plot. Then, use the SCATTER statement to create the scatterplot. Next, use the REG statement to add a regression line to the plot. You can customize the appearance of the plot and regression line by using various options within the PROC SGPLOT procedure. Finally, use the RUN statement to execute the procedure and generate the scatterplot with the regression line. This will allow you to visualize the relationship between your variables and assess the strength and direction of the linear relationship.
Create a Scatterplot with Regression Line in SAS
You can use proc sgplot to quickly create a scatterplot with a regression line in SAS.
The following examples show how to use this procedure in practice.
Example 1: Create Basic Scatterplot with Regression Line
The following code shows how to create a basic scatterplot with a regression line using the built-in SAS :
/*create scatterplot with regression line*/
proc sgplotdata=sashelp.class;
regy=height x=weight;
run;
The points in the plot display the individual from the dataset and the blue line displays the fitted regression line.
Example 2: Create Custom Scatterplot with Regression Line
Note that proc sgplot can create highly customizable scatterplots.
For example, you can:
- Add a title to the chart
- Modify the axis labels
- Remove the legend
- Customize the color and thickness of the regression line
- Customize the appearance of the points in the plot
The following code shows how to customize each of these aspects of the plot:
/*create custom scatterplot with regression line*/
proc sgplot data=sashelp.class noautolegend;
title 'Regression Model';
xaxislabel='Weight (pounds)';
yaxislabel='Height (inches)';
regy=height x=weight /
lineattrs=(color=red thickness=2)
markerattrs=(color=green size=12px symbol=circlefilled);
run;
Notice that the title, axis labels, individual points, and the regression line have all been modified.
Additional Resources
The following tutorials explain how to perform other common tasks in SAS:
Cite this article
stats writer (2024). How can I create a scatterplot with a regression line in SAS?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-create-a-scatterplot-with-a-regression-line-in-sas/
stats writer. "How can I create a scatterplot with a regression line in SAS?." PSYCHOLOGICAL SCALES, 1 Jul. 2024, https://scales.arabpsychology.com/stats/how-can-i-create-a-scatterplot-with-a-regression-line-in-sas/.
stats writer. "How can I create a scatterplot with a regression line in SAS?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-create-a-scatterplot-with-a-regression-line-in-sas/.
stats writer (2024) 'How can I create a scatterplot with a regression line in SAS?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-create-a-scatterplot-with-a-regression-line-in-sas/.
[1] stats writer, "How can I create a scatterplot with a regression line in SAS?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, July, 2024.
stats writer. How can I create a scatterplot with a regression line in SAS?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
