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

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 628 views
  • 0 likes
  • 2 in conversation