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.png

 

Time is running out to save with the early bird rate. Register by Friday, March 1 for just $695 - $100 off the standard rate.

 

Check out the agenda and get ready for a jam-packed event featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events. 

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

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