panel1

How to Use PROC SGPANEL in SAS?

Understanding PROC SGPANEL: An Overview

The PROC SGPANEL is a powerful graphical procedure within the SAS System designed specifically for the comparative visualization of data. Its primary function is to generate a panel of graphs, allowing users to display multiple plots simultaneously within a single, cohesive output. This capability is exceptionally valuable in analytical environments where rapid comparison between different variables, subgroups, or conditions is necessary for a given analysis.

Unlike procedures that generate only one graph at a time, PROC SGPANEL streamlines the workflow by producing conditional plots—where the plot structure remains consistent, but the underlying data is partitioned based on categorical variables. This procedure supports a wide range of graphical outputs, including scatter plots, line plots, box plots, and histograms. By leveraging the comprehensive graphical parameter language available in SAS, analysts can precisely tailor the appearance and arrangement of these paneled graphs to meet specific analytical requirements and presentation standards.


The Essential Syntax: Grouping Data with PANELBY

The cornerstone of PROC SGPANEL functionality is the mandatory PANELBY statement. This statement dictates how the input dataset is segmented, effectively defining the categorical variables that will determine the number and content of the individual plots within the panel. For every unique combination of values specified in the PANELBY statement, a separate plot is generated, allowing for complex comparative displays grouped by one or more variables.

In practice, using PROC SGPANEL typically involves one of two fundamental approaches, depending on the complexity of the grouping required. The decision hinges on whether the visualization needs to be segmented by a single factor or by the intersection of multiple factors.

Method 1: Creating Plots Grouped by a Single Variable

The simplest and most common application involves partitioning the data based on a single categorical variable. This method generates a sequence of plots, one for each level found within that chosen variable. This is highly effective for quick comparative analysis across distinct groups within the same measure, such as comparing the distribution of scores across different teams.

Below is the standard syntax for grouping plots by a single variable, using the team variable as the segmenting factor.

title "Points Distribution by Team";
proc sgpanel data=my_data;
  panelby team / novarname;
  histogram points;
run;

In this particular example, the procedure creates a panel of histograms. The PANELBY statement instructs SAS to generate separate plots showing the distribution of the points variable, conditional upon the unique values of the team variable. The NOVARDNAME option is utilized to ensure a cleaner visual presentation by suppressing the categorical variable name from appearing in the panel header.

Method 2: Grouping Plots by Multiple Variables

For more granular comparisons and visualizations of interactions, PROC SGPANEL allows grouping by multiple variables simultaneously. When two or more variables are listed in the PANELBY statement, the procedure creates a plot for every possible unique intersection of those variables, offering detailed insight into multivariate relationships.

title "Points Distribution by Team and Position";
proc sgpanel data=my_data;
  panelby team position / layout=lattice novarname;
  histogram points;
run;

This code creates a panel of histograms that show the distribution of values for the points variable, grouped by the unique combinations of the team and position variables. The LAYOUT=LATTICE option is particularly useful here as it instructs SAS to arrange the resulting plots in an optimized grid structure, facilitating efficient visual comparison of the four resulting subgroups.

Setting Up the Sample Dataset in SAS

To effectively demonstrate the capabilities of PROC SGPANEL, we utilize a small, simulated dataset named my_data. This dataset contains performance metrics for two teams (A and B) across two positions (Guard and Forward). The variables included are:

  • team: Categorical identifier for the team (A or B).
  • position: Categorical identifier for the player’s position (Guard or Forward).
  • points: A continuous variable representing the points scored.
  • assists: A continuous variable representing the number of assists.

The following SAS code block shows the steps taken to create this sample data using the DATA step.

/*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;

The output from PROC PRINT confirms the successful creation and structure of our analytical data source, ensuring that the subsequent PROC SGPANEL calls will execute correctly, as shown below.

Example 1: Visualizing Points Distribution Grouped by Team

For our first practical demonstration, we focus on generating comparative histograms that illustrate the distribution of the points variable, separated by each unique value found in the team column. This approach allows us to immediately assess whether the scoring profiles differ significantly between Team A and Team B. We use the following syntax:

title "Points Distribution by Team";
proc sgpanel data=my_data;
  panelby team / novarname;
  histogram points;
run;

 

The resulting panel automatically arranges the two histograms side-by-side (the default layout), clearly separating the point distribution for Team A (left) and Team B (right), providing an immediate visual contrast of their underlying scoring patterns.

Customizing Panel Arrangement: Vertical Stacking with ROWS Option

While the default side-by-side arrangement is highly effective, visualization preferences sometimes require a vertical orientation, especially when optimizing the display for reports or sequential presentations. PROC SGPANEL provides granular control over the layout through options specified after the PANELBY statement.

To force the two panels (Team A and Team B) to stack vertically, we use the ROWS=2 option. This instructs SAS to arrange the resulting plots into two distinct rows, ensuring the output fits vertically.

title "Points Distribution by Team";
proc sgpanel data=my_data;
  panelby team / rows=2 novarname;
  histogram points;
run;

The output below shows the Team A histogram on the top and the Team B histogram on the bottom, maintaining clarity while adjusting the orientation.

Example 2: Multivariate Grouping by Team and Position

When the analysis requires segmenting the data based on more than one characteristic, we utilize multivariate grouping. Here, we visualize the distribution of points segmented by both team and position, resulting in four distinct panels corresponding to every unique combination.

The syntax requires listing both grouping variables in the PANELBY statement. We explicitly include the LAYOUT=LATTICE option to ensure optimal arrangement of the increased number of resulting plots in a grid.

title "Points Distribution by Team and Position";
proc sgpanel data=my_data;
  panelby team position / layout=lattice novarname;
  histogram points;
run;

This code generates a 2×2 grid of histograms, allowing for sophisticated comparative assessments.

PROC SGPANEL example in SAS

The four resulting histograms show the distribution of points for each unique combination of the values in the team and position columns, providing detailed segment-specific insights from the source dataset.

Exploring Diverse Plot Types within PROC SGPANEL

While the preceding examples focused exclusively on generating histograms to illustrate data distribution, PROC SGPANEL is highly versatile. It supports nearly all graph statements available in the SAS Statistical Graphics (SG) Procedures, allowing analysts to choose the visualization best suited for their data type and research question.

Instead of using the HISTOGRAM statement, users can substitute other plot statements to achieve different visual outputs while maintaining the same panel structure defined by the PANELBY variables. Common alternatives include:

  • VBOX and HBOX: Used for creating vertical or horizontal box plots, essential for visualizing quartile distributions and identifying outliers across groups.
  • SCATTER: Used for generating scatter plots, ideal for examining the relationship between two continuous variables within each defined subgroup.

Summary and Further Resources

PROC SGPANEL provides an essential mechanism in SAS for generating comparative graphical displays. By mastering the PANELBY statement, analysts can quickly produce complex visualizations, whether grouping by a single factor or multiple interacting variables, thereby significantly enhancing data exploration and reporting efficiency.

For comprehensive details regarding all available options, layouts, and plot statements supported by this procedure, readers are highly encouraged to consult the official SAS documentation for PROC SGPANEL.

The following tutorials explain how to create other charts in SAS:

Cite this article

stats writer (2025). How to Use PROC SGPANEL in SAS?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-to-use-proc-sgpanel-in-sas/

stats writer. "How to Use PROC SGPANEL in SAS?." PSYCHOLOGICAL SCALES, 19 Nov. 2025, https://scales.arabpsychology.com/stats/how-to-use-proc-sgpanel-in-sas/.

stats writer. "How to Use PROC SGPANEL in SAS?." PSYCHOLOGICAL SCALES, 2025. https://scales.arabpsychology.com/stats/how-to-use-proc-sgpanel-in-sas/.

stats writer (2025) 'How to Use PROC SGPANEL in SAS?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-to-use-proc-sgpanel-in-sas/.

[1] stats writer, "How to Use PROC SGPANEL in SAS?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, November, 2025.

stats writer. How to Use PROC SGPANEL in SAS?. PSYCHOLOGICAL SCALES. 2025;vol(issue):pages.

Download Post (.PDF)
Slide Up
x
PDF
Scroll to Top