Paired-Bar Charts
As I was reading about SAS 9.2 SGPLOT, I came across a resource with some wonderful images and SAS code explaining "Paired-Bar Charts" and other things. This is exactly what I was looking for months ago, but I didn't know that that type of chart was called a Paired-Bar Chart. So when I did searches and asked the folks on the SAS Google Groups, I was having difficulty describing what I wanted.
I did eventually come up with my own code, but it involved some significant coding which I won't replicate here. In fact, I'm scrapping the code I wrote and will be incorporating this new stuff.
But some of the stuff on on the above link is far better. Robert Allison, thank you!!!
Here is an example of the paired-bar chart:
%let name=bar4;
filename odsout '.';
/* You have to make some values 'negative' so they'll show up on
the left side of the zero axis, but you want their labels to
show the positive value. Use a user-defined format to
accomplish this. */
proc format; picture posval low-high='000,009'; run;
data a;
input ITEM $ 1-6 left right;
format amount posval.;
illusion='Group 1'; amount=-1*left; output;
illusion='Group 2'; amount=right; output;
cards;
ITEM A 41 58
ITEM B 53 51
ITEM C 42 33
ITEM D 23 28
ITEM E 12 17
ITEM F 18 13
;
run;
data a; set a;
length htmlvar $500;
htmlvar='title='||quote(
'Item: '|| trim(left(item)) ||'0D'x||
'Group 1: '|| trim(left(left)) ||'0D'x||
'Group 2: '|| trim(left(right))
)
||' '||
'href="bar5.htm"';
run;
GOPTIONS DEVICE=gif;
ODS LISTING CLOSE;
ODS HTML path=odsout body="&name..htm"
(title="Paired-Bar Chart")
style=minimal
gtitle gfootnote
;
goptions noborder;
goptions gunit=pct htitle=6 ftitle="swissb" htext=5 ftext="swiss";
axis1 label=none;
axis2 label=none order=(-60 to 60 by 10) minor=none offset=(0,0) value=(h=3pct);
pattern1 v=solid color=cxbd0026; /* reddish color */
pattern2 v=solid color=cx43a2ca; /* this is the hex rgb color for mild blue */
legend1 label=none position=(bottom) cframe=white
shape=bar(3,3) cborder=white across=2;
title "Paired-Bar Chart";
proc gchart data=a;
hbar item / discrete
type=sum sumvar=amount
subgroup=illusion /* this controls the coloring */
nostats
maxis=axis1 /* midpoint axis */
raxis=axis2 /* response/numeric axis */
autoref /* reflines at every major axis tickmark */
clipref /* put reflines 'behind' the bars */
legend=legend1
coutline=same
html=htmlvar
des="" name="&name" ;
run;
quit;
ODS HTML CLOSE;
ODS LISTING;


Reader Comments