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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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