Table of Contents
PROC SGPANEL is a powerful SAS procedure that allows users to create panel or multi-panel graphs, also known as trellis plots, to display data in a visually appealing and informative manner. This procedure can be used to compare multiple variables or groups in a single graph, making it useful for analyzing complex data sets.
To use PROC SGPANEL, users must first specify the variables to be plotted and the panel variables that define the groups or panels. Next, they can customize the appearance of the graph by adding titles, labels, legends, and other design elements. Users can also add statistical features, such as means, medians, or confidence intervals, to the graph to enhance their analysis.
Some examples of how PROC SGPANEL can be used include comparing sales data across different regions or time periods, analyzing the impact of different treatments on patient outcomes, or examining the relationship between multiple variables in a scientific study. This procedure is highly versatile and can be applied to a wide range of data analysis tasks, making it a valuable tool for researchers, analysts, and professionals in various fields.
Use PROC SGPANEL in SAS (With Examples)
You can use the PROC SGPANEL statement in SAS to create multiple plots in a panel layout that are grouped by one or more variables in a dataset.
Here are two common ways to use this statement in practice:
Method 1: Use PROC SGPANEL to Create Multiple Plots Grouped by One Variable
title "Points Distribution by Team";
proc sgpaneldata=my_data;
panelby team / novarname;
histogram points;
run;
This particular example creates a panel of histograms that show the distribution of values for the points variable, grouped by the unique values of the team variable.
Method 2: Use PROC SGPANEL to Create Multiple Plots Grouped by Multiple Variables
title "Points Distribution by Team and Position";
proc sgpaneldata=my_data;
panelby team position / layout=lattice novarname;
histogram points;
run;This particular example creates a panel of histograms that show the distribution of values for the points variable, grouped by the unique values of the team and position variables.
Note that in these examples we used the histogram statement to create histograms, but you could use vbox, hbox, scatter or other statements to instead create vertical boxplots, horizontal boxplots, scatter plots, etc.
The following examples show how to use each method in practice using the following dataset in SAS:
/*create dataset*/
data my_data;
input team $ position $ points assists;
datalines;
A Guard 14 4
A Guard 22 6
A Guard 24 9
A Forward 13 8
A Forward 13 9
A Guard 10 5
A Guard 20 6
A Guard 34 9
A Forward 33 8
A Forward 15 5
B Guard 24 4
B Guard 22 6
B Forward 34 2
B Forward 15 5
B Forward 23 5
B Guard 10 4
B Guard 12 6
B Forward 30 2
B Forward 15 5
B Forward 11 5
;
run;
/*view dataset*/
proc printdata=my_data;
Example 1: Use PROC SGPANEL to Create Multiple Plots Grouped by One Variable
We can use the following syntax with PROC SGPANEL to create a panel of plots that display a histogram of points for each unique value in the team column:
title "Points Distribution by Team";
proc sgpaneldata=my_data;
panelby team / novarname;
histogram points;
run;

If you would instead like to stack the panels on top of each other, you can use the rows statement to specify that there should be 2 rows in the panel layout:
title "Points Distribution by Team";
proc sgpaneldata=my_data;
panelby team / rows=2novarname;
histogram points;
run;
The histogram on the top shows the distribution of points for team A and the histogram on the bottom shows the distribution of points for team B.
Example 2: Use PROC SGPANEL to Create Multiple Plots Grouped by Multiple Variables
We can use the following syntax with PROC SGPANEL to create a panel of plots that display a histogram of points for each unique value in the team and position columns:
title "Points Distribution by Team";
proc sgpaneldata=my_data;
panelby team position / layout=lattice novarname;
histogram points;
run;
The four histograms show the distribution of points for each unique combination of the values in the team and position columns.
Note: You can find the complete documentation for the PROC SGPANEL statement in SAS .
The following tutorials explain how to create other charts in SAS:
Cite this article
stats writer (2024). How can I use PROC SGPANEL in SAS and what are some examples?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-use-proc-sgpanel-in-sas-and-what-are-some-examples/
stats writer. "How can I use PROC SGPANEL in SAS and what are some examples?." PSYCHOLOGICAL SCALES, 23 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-i-use-proc-sgpanel-in-sas-and-what-are-some-examples/.
stats writer. "How can I use PROC SGPANEL in SAS and what are some examples?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-use-proc-sgpanel-in-sas-and-what-are-some-examples/.
stats writer (2024) 'How can I use PROC SGPANEL in SAS and what are some examples?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-use-proc-sgpanel-in-sas-and-what-are-some-examples/.
[1] stats writer, "How can I use PROC SGPANEL in SAS and what are some examples?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.
stats writer. How can I use PROC SGPANEL in SAS and what are some examples?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
