BookmarkSubscribeRSS Feed
keen_sas
Quartz | Level 8
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.
4 REPLIES 4
DanH_sas
SAS Super FREQ
What version of SAS are you using?
ArtC
Rhodochrosite | Level 12
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.
keen_sas
Quartz | Level 8
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.
GraphGuy
Meteorite | Level 14
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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 937 views
  • 0 likes
  • 4 in conversation