When the data is classified by multiple class variables, you can certainly create graphs using BY variables. This results in separate graphs, one for each level of the BY variable crossings. Each graph is scaled by its own data subset, and comparisons across BY levels is harder.
When comparisons need to be made across by variable levels, a classification panel is useful. The SGPANEL procedure is a great tool to create such classification panel graphs. Based on the need, panels can be in columns, rows or both. The SGPANEL procedure supports multiple types of layouts for the panel, and you can select the one most suitable for your needs. These are:
- Panel (default) - supports multiple class variables. Only cells that have data are displayed. Cell headers show the class values.
- Lattice - for Row x Column layout, one class variable each. All crossings are displayed with column and row headers.
- RowLattice - Lattice of rows. Row headers are shown on the side.
- ColumnLattice - Lattice of columns. Column headers are shown at top (or bottom).
Here is a histogram of mileage for all the cars (except Hybrids) for the SASHELP.CARS data set:
title "Mileage Distribution"; proc sgplot data=sashelp.cars; where type ne 'Hybrid'; histogram mpg_city; density mpg_city; density mpg_city / type=kernel; xaxis display=(nolabel); yaxis grid; run;
This data is classified by country of origin. To compare car mileage by ORIGIN we can create a panel by ORIGIN arranged as multiple columns in one row, useful to compare the density magnitude across cells:
title "Mileage Distribution"; proc sgpanel data=sashelp.cars; where type ne 'Hybrid'; panelby origin / novarname rows=1; histogram mpg_city; density mpg_city; density mpg_city / type=kernel; colaxis display=(nolabel); rowaxis grid; run;
Only change needed it to replace the SGPLOT procedure with the SGPANEL procedure along with the PANELBY statement. To compare the distribution of the data along the analysis variable, we could arrange the panel as multiple cells in one column, as follows:
title "Mileage Distribution"; proc sgpanel data=sashelp.cars; where type ne 'Hybrid'; panelby origin / novarname layout=rowlattice; histogram mpg_city; density mpg_city; density mpg_city / type=kernel; colaxis display=(nolabel); rowaxis grid; run;
The LAYOUT=LATTICE option creates a Row x Column panel as shown below with ORIGIN and TYPE as class variables:
title "Mileage by Horsepower"; proc sgpanel data=sashelp.cars; where type eq 'Sedan' or type eq 'Sports' or type eq 'Wagon'; panelby origin type / novarname layout=lattice onepanel; scatter x=horsepower y=mpg_city / markerattrs=(symbol=circlefilled) transparency=0.8; reg x=horsepower y=mpg_city / nomarkers; colaxis grid; rowaxis grid; run;
The class panel is useful to identify the anomaly in the "Barley" data set as discussed in this paper. I have reduced the data just for demonstration purposes.
title "Barley Yield by Variety"; proc sgpanel data=barley; panelby site / novarname layout=rowlattice onepanel; dot variety / response=yield group=year markerattrs=(size=11); discretelegend; rowaxis display=(nolabel); run;
SAS Code: Class_Panels