How to Use PROC SGPANEL in SAS?

PROC SGPANEL is a SAS procedure used to create a panel of graphs. It allows a user to produce multiple plots in a single display, which can be useful for comparing different variables or different groups for a given analysis. The procedure can include a variety of plot types such as scatter plots, line plots, box plots, histograms, and more. Using SAS’s graphical parameter language, PROC SGPANEL can be tailored to the specific needs of the user.


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 sgpanel data=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 sgpanel data=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 print data=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 sgpanel data=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 sgpanel data=my_data;
  panelby team / rows=2 novarname;
  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 sgpanel data=my_data;
  panelby team position / layout=lattice novarname;
  histogram points;
run;

PROC SGPANEL example in SAS

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:

x