Hello Experts,
I use SAS 9.4 and am trying to plot bar charts with confidence intervals using proc sgplot. I want to differentiate one bar from the others by using a different color and created a column for group, assigning '1' to it and '2' to the rest.
'Test' is the output without assigning color to the groups
'Test1' is the output when I assign color (notice the error bars are gone)
I would like to have the different colors but retain the error bars and remove the group label at the bottom of the chart. See code below:
For test
/*Plot age group*/
ods listing gpath="&path/tasks/stl_conf/conf_new";
ods graphics / imagename="test1" imagefmt=png;
proc sgplot data=hist2.pop_by_age1;
styleattrs datacolors=(STYBR LIGRYBR);
vbarparm category=age_group response=Delta_Age /
limitlower=L_Age limitupper=U_Age;
title 'City Population Change by Age Group';
yaxis label='Population change';
xaxis label='Age';
run;
For test1
/*Plot age group*/
ods listing gpath="&path/tasks/stl_conf/conf_new";
ods graphics / imagename="test1" imagefmt=png;
proc sgplot data=hist2.pop_by_age1;
styleattrs datacolors=(STYBR LIGRYBR);
vbarparm category=age_group response=Delta_Age / group=group
limitlower=L_Age limitupper=U_Age;
title 'City Population Change by Age Group';
yaxis label='Population change';
xaxis label='Age';
run;
Thank you.
To get rid of the legend, specify NOAUTOLEGEND on the PROC SGPLOT statement. To get your error bars back, you need to specify GROUPDISPLAY=CLUSTER on the VBARPARM statement. By default, grouped bars are STACKed, which does not support error bars, causing them to be dropped.
Hope this helps!
Dan
To get rid of the legend, specify NOAUTOLEGEND on the PROC SGPLOT statement. To get your error bars back, you need to specify GROUPDISPLAY=CLUSTER on the VBARPARM statement. By default, grouped bars are STACKed, which does not support error bars, causing them to be dropped.
Hope this helps!
Dan
Thank you so much. It works.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.