BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
michokwu
Quartz | Level 8

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.

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

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

View solution in original post

2 REPLIES 2
DanH_sas
SAS Super FREQ

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

michokwu
Quartz | Level 8

Thank you so much. It works.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1236 views
  • 0 likes
  • 2 in conversation