Dear All,
I'm working with PROC SGPANEL to create side-by-side bar charts for two different metrics (e.g., Response Rate and Adverse Event Rate), each associated with a distinct set of treatment groups:
Response Rate: Treatments 1, 2, 3
Adverse Event Rate: Treatments 4, 5, 6
When using PROC SGPANEL, I get empty categories (Trt4, Trt5, Trt6) displayed in the Response panel, and Trt1–3 in the Adverse panel — even though those combinations do not exist in the data.
I've tried using:
categoryorder=data
layout=columnlattice and onepanel
Formatting Treatment with proc format
But the empty bars still appear.
Below is my SAS code for you reference. how can this be fixed?
data treatment_data;
input Treatment Metric $ Value;
datalines;
1 ResponseRate 75
2 ResponseRate 65
3 ResponseRate 80
4 AdverseEventRate 20
5 AdverseEventRate 25
6 AdverseEventRate 15
;
run;
/* Create dynamic treatment labels */
data treatment_data_labeled;
set treatment_data;
length TreatmentLabel $10;
TreatmentLabel = "Trt" || strip(put(Treatment, 1.));
run;
ods graphics / width=800px height=400px;
proc sgpanel data=treatment_data_labeled;
panelby Metric / onepanel novarname;
vbar TreatmentLabel / response=Value datalabel
fillattrs=(color=steelblue)
stat=mean;
colaxis display=(nolabel);
rowaxis label="Percentage";
title "Bar Charts for Treatments by Metric";
run;
Thanks a lot fotr your help
The default behavior for SGPANEL Panelby statement is to use UNISCALE=ALL, meaning the row and column axis appear the same for each panel. You can get different column axis appearance by using UNISCALE=ROW.
proc sgpanel data=treatment_data_labeled; panelby Metric / onepanel novarname uniscale=row; vbar TreatmentLabel / response=Value datalabel fillattrs=(color=steelblue) stat=mean; colaxis display=(nolabel); rowaxis label="Percentage"; title "Bar Charts for Treatments by Metric"; run;
The default behavior for SGPANEL Panelby statement is to use UNISCALE=ALL, meaning the row and column axis appear the same for each panel. You can get different column axis appearance by using UNISCALE=ROW.
proc sgpanel data=treatment_data_labeled; panelby Metric / onepanel novarname uniscale=row; vbar TreatmentLabel / response=Value datalabel fillattrs=(color=steelblue) stat=mean; colaxis display=(nolabel); rowaxis label="Percentage"; title "Bar Charts for Treatments by Metric"; run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.