Data visualization with SAS programming

errorbars on subcategory of stacked vertical bar chart.

Reply
Contributor
Posts: 30

errorbars on subcategory of stacked vertical bar chart.

Hi All ,

How do you create errorbars on top of each subcategory of stacked vertical bars . errorbar=option will not work if we use subgroup=option in proc gchart. I tried doing this using annotate dataset, but could not coincide on each top of subcategory in vertical bar chart.

For ex i have 3 subcategories in a single vertical bar and on each top i have to produce a T shaped errorbar on each subcategory (total 3 errorbars on one vertical bar chart) .Can anyone please help me in solving this.
SAS Super FREQ
Posts: 925

Re: errorbars on subcategory of stacked vertical bar chart.

What version of SAS are you using?
Valued Guide
Posts: 632

Re: errorbars on subcategory of stacked vertical bar chart.

I have an admitted bias against stacked histograms, I prefer GROUP= to SUBGROUP= where the error bars make more sense.

That said you should be able to calculate the height of each subgroup and therefore the location to place the bars using annotate.
Contributor
Posts: 30

Re: errorbars on subcategory of stacked vertical bar chart.

I am using sas 8.2 version. We can define only one group variable. I have used both group and subgroup options. Can any one please elaborate the method to define it.
SAS Employee
Posts: 980

Re: errorbars on subcategory of stacked vertical bar chart.

Here is one way to do it with gchart and annotate...

---

%let name=anno002;
filename odsout '.';

data foo;
input barmid $ 1-1 subgr $ 3-3 value err;
datalines;
A x 10 2
A y 15 1.5
A z 7 1.1
C y 10 1.6
C x 11 2.2
C z 17 2.4
B x 3 1.5
B y 6 1.3
;
run;

proc sort data=foo out=foo_anno;
by barmid subgr;
run;

data foo_anno; set foo_anno;
by barmid;
xsys='2'; ysys='2'; when='a';
if first.barmid then y_base=0;
y_base+value;
midpoint=barmid;
function='move'; y=y_base; output;
function='draw'; y=y+err; output;
xsys='7'; x=-1; output; x=+2; output; /* draw the 'T' across the top */
run;

goptions device=png;

ODS LISTING CLOSE;
ODS HTML path=odsout body="&name..htm" style=sasweb;

goptions gunit=pct htitle=4.5 ftitle="albany amt/bold" htext=3.0 ftext="albany amt";

axis1 label=none order=(0 to 50 by 10) minor=none offset=(0,0);
axis2 label=none;


proc gchart data=foo anno=foo_anno;
vbar barmid / type=sum sumvar=value
subgroup=subgr
raxis=axis1 maxis=axis2
nolegend
width=10
coutline=graycc
des='' name="&name";
run;

proc print data=foo_anno;
run;

quit;
ODS HTML CLOSE;
ODS LISTING;
Ask a Question
Discussion stats
  • 4 replies
  • 228 views
  • 0 likes
  • 4 in conversation