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

This maybe just me being stubborn but I refuse to believe that I can't get error bars in a barchart statement using proc template.  The documentation indicates no love but I just don't buy it.  I can get error bars from barchartparm in proc template. I can get error bars from vbar in sgplot.   So how do I get an error bar in a barchart statement in proc template?    If the answer is "You can't get an error bar from barchart" can someone point me to the complaint/feature request page?  I have a long, expletive laden rant to unload! :smileylaugh:   j/k.

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Jay54
Meteorite | Level 14

You are right, this option is not available on the BarChart statement, so please proceed with your rant to SAS Tech Support. Smiley Happy 

To get error bars with BarChart in GTL (proc template) you have to precompute the mean and limits and use BarChartParm.  The reasoning was that SAS users are experts at this (proc means) and an option is not needed. This also supports custom computed limits.  Subsequently it has become evident that such a convenience option on the BarChart itself would be useful and is planned for a future release.

VBAR in SGPLOT computes the limits for you and then simply does something similar. You can extract the generated template from SGPLOT using TMPLOUT='finename' and inspect the code.

View solution in original post

2 REPLIES 2
Jay54
Meteorite | Level 14

You are right, this option is not available on the BarChart statement, so please proceed with your rant to SAS Tech Support. Smiley Happy 

To get error bars with BarChart in GTL (proc template) you have to precompute the mean and limits and use BarChartParm.  The reasoning was that SAS users are experts at this (proc means) and an option is not needed. This also supports custom computed limits.  Subsequently it has become evident that such a convenience option on the BarChart itself would be useful and is planned for a future release.

VBAR in SGPLOT computes the limits for you and then simply does something similar. You can extract the generated template from SGPLOT using TMPLOUT='finename' and inspect the code.

GraphGuy
Meteorite | Level 14

Although you're asking for proc template code ... I thought it might be worth showing you some Proc Gchart code where I annotate error bars on the bar chart (hopefully the spacing in the data lines won't get messed up too much in the copy-n-paste).  This is an adapted version of Example 10 in my new book "SAS/GRAPH: Beyond the Basics"...

data repdata;
input Name $ 1-20 lower_whisker lower_box Median upper_box upper_whisker;
datalines;
Allison, R           0.5 6.1  8.2 11.0 17.5
Jeffreys, E          1.0 5.8  9.5 13.0 20.2
Peterson, B          3.0 8.8 11.0 13.1 17.2
Proctor, L           2.0 6.1  9.0 11.5 16.0
Taylor, C            1.5 5.5  9.0 12.6 18.7
Davis, J             2.5 6.0  9.3 11.8 14.8
;
run;

%let boxwidth=1.5;
%let linewidth=.5;
%let linecolor=black;
%let boxcolor=cxCAE1FF;

data repanno; set repdata;
xsys='2'; ysys='2'; hsys='3'; when='a';
length function color $8 style $15;

size=&linewidth;

/* draw the whiskers */
color="&linecolor";
ysys='2'; midpoint=Name;
function='move'; x=lower_whisker; output;
function='draw'; x=upper_whisker; output;

/* draw the ends on the whiskers */
color="&linecolor";
ysys='2'; midpoint=Name;
function='move'; x=lower_whisker; output;
function='move'; ysys='7'; y=-1*&boxwidth; output;
function='draw'; line=1; y=+2*&boxwidth; output;
ysys='2'; midpoint=Name;
function='move'; x=upper_whisker; output;
function='move'; ysys='7'; y=-1*&boxwidth; output;
function='draw'; line=1; y=+2*&boxwidth; output;

/* draw the box, using annotate 'bar' function */
color="&boxcolor";
ysys='2'; midpoint=Name;
function='move'; x=lower_box; output;
function='move'; ysys='7'; y=-1*&boxwidth; output;
function='bar'; line=0; style='solid'; x=upper_box; y=+2*&boxwidth; output;
color="&linecolor";
ysys='2'; midpoint=Name;
function='move'; x=lower_box; output;
function='move'; ysys='7'; y=-1*&boxwidth; output;
function='bar'; line=0; style='empty'; x=upper_box; y=+2*&boxwidth; output;

/* Median Line */
color="&linecolor";
ysys='2'; midpoint=Name;
function='move'; x=Median; output;
function='move'; ysys='7'; y=-1*&boxwidth; output;
function='draw'; line=1; y=+2*&boxwidth; output;

run;

goptions gunit=pct htitle=5 ftitle="albany amt/bold" htext=3.0 ftext="albany amt" ctext=gray33;

axis1 order=(0 to 25 by 5) minor=none label=none offset=(0,0);

pattern1 v=solid c=red;

title1 ls=1.5 "Annotated Boxplot on Gchart";
proc gchart data=repdata anno=repanno;
hbar name / type=sum sumvar=median
raxis=axis1 autoref cref=graydd clipref;
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1898 views
  • 0 likes
  • 3 in conversation