Table of Contents
SAS (Statistical Analysis System) is a powerful software tool commonly used in data analysis and visualization. PROC SGPLOT is a SAS procedure that allows for the creation of high-quality graphs and plots. It offers a wide range of customizable options to display data in a visually appealing and informative manner.
One of the key features of PROC SGPLOT is its ability to plot groups, or subsets of data with similar characteristics. This can be achieved by specifying a grouping variable in the procedure, which will automatically generate separate graphs for each group.
Using PROC SGPLOT to plot groups allows for a quick and efficient way to compare and analyze data between different categories. The resulting graphs can also be further customized with various formatting options and statistical annotations.
Overall, the combination of SAS and PROC SGPLOT provides a powerful tool for effectively visualizing and analyzing data with groupings, making it a valuable resource for researchers, analysts, and businesses.
SAS: Plot Groups Using PROC SGPLOT
You can use the following methods to plot groups using PROC SGPLOT in SAS:
Method 1: Plot Each Group in Separate Charts
/*create multiple plots that show histogram of points for each team*/
proc sgplotdata=my_data;
by team;
histogram points;
density points / type=kernel;
run;
The by statement tells SAS to create a separate histogram for each unique value in the team column.
Method 2: Plot Each Group in One Chart
/*plot histogram of points for each team on one chart*/
proc sgplotdata=my_data;
histogram points / group=team;
density points / type=kernel group=team;
run;The group statement tells SAS to display a separate histogram for each unique value in the team column overlaid on the same chart.
The following examples show how to use each method with the following dataset in SAS:
/*create dataset*/
data my_data;
input team $ points;
datalines;
A 29
A 23
A 20
A 21
A 33
A 35
A 31
B 21
B 14
B 15
B 11
B 12
B 10
B 15
;
run;
/*view dataset*/
proc printdata=my_data;
Example 1: Use PROC SGPLOT to Plot Each Group in Separate Charts
We can use the by statement in PROC SGPLOT to create individual histograms that show the distribution of points for each team:
/*create multiple plots that show histogram of points for each team*/
proc sgplotdata=my_data;
by team;
histogram points;
density points / type=kernel;
run;

The first histogram displays the distribution of points for team A and the second histogram displays the distribution of points for team B.
Note: The density statement is optional, but it displays a for each histogram which can be a helpful way to summarize the shape of the distribution.
Example 2: Use PROC SGPLOT to Plot Each Group in One Chart
We can use the group statement in PROC SGPLOT to create one chart that contains overlaid histograms of the distribution of points for each team:
/*plot histogram of points for each team on one chart*/
proc sgplotdata=my_data;
histogram points / group=team transparency=0.5;
density points / type=kernel group=team;
run;
The blue histogram displays the distribution of points values for team A and the red histogram displays the distribution of points values for team B.
The benefit of using this approach is that we can quickly compare the distribution of points values for each team since each histogram is placed on the same chart.
Note: The transparency argument makes the histograms transparent and easier to read when they overlap. The closer you set this value to 1, the more transparent the histograms become.
The following tutorials explain how to create other charts in SAS:
Cite this article
stats writer (2024). How can SAS be used to plot groups using PROC SGPLOT?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-sas-be-used-to-plot-groups-using-proc-sgplot/
stats writer. "How can SAS be used to plot groups using PROC SGPLOT?." PSYCHOLOGICAL SCALES, 23 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-sas-be-used-to-plot-groups-using-proc-sgplot/.
stats writer. "How can SAS be used to plot groups using PROC SGPLOT?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-sas-be-used-to-plot-groups-using-proc-sgplot/.
stats writer (2024) 'How can SAS be used to plot groups using PROC SGPLOT?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-sas-be-used-to-plot-groups-using-proc-sgplot/.
[1] stats writer, "How can SAS be used to plot groups using PROC SGPLOT?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.
stats writer. How can SAS be used to plot groups using PROC SGPLOT?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
