Data visualization with SAS programming

Error bars in a barchart statement

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

Error bars in a barchart statement

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.


Accepted Solutions
Solution
‎03-14-2012 12:59 AM
SAS Super FREQ
Posts: 1,044

Error bars in a barchart statement

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


All Replies
Solution
‎03-14-2012 12:59 AM
SAS Super FREQ
Posts: 1,044

Error bars in a barchart statement

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.

SAS Employee
Posts: 963

Error bars in a barchart statement

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;

Post a Question
Discussion Stats
  • 2 replies
  • 308 views
  • 0 likes
  • 3 in conversation