%let name=life;
Filename odsout '.';

/* 
I'm using numeric country & sex values so I can sort the
maxis the way I want.  I then use user-defined formats to
print the text value I want. 
*/

data my_data;
input country sex age;
datalines;
1 1 73
1 2 78
2 1 77 
2 2 84
3 1 75
3 2 80
4 1 74
4 2 80
5 1 76
5 2 80
6 1 71
6 2 78
7 1 64
7 2 70
;
run;

proc format;
 value countries
 1='Republic\of China'
 2='Japan'
 3='United\Kingdom'
 4='United\States'
 5='Singapore'
 6='South\Korea'
 7='Philippines'
 ;
run;

proc format;
 value sexes
 1='Male'
 2='Female'
 ;
run;

data my_data; set my_data;
length myhtml $300;
myhtml=
 'title='||quote(
  'Country: '||trim(left(translate(put(country,countries.),'','\')))||'0D'x||
  'Sex: '||trim(left(put(sex,sexes.)))||'0D'x||
  'Life Expectancy: '||trim(left(age)))||
 ' href='||quote('http://en.wikipedia.org/wiki/Life_expectancy');
run;

data my_anno; set my_data;
length function color $8 text $30;
xsys='2'; ysys='2'; when='a'; 
function='label'; position='5'; style='marker'; size=3;
if sex eq 1 then do;
 color='green';
 text='Q';
end;
else if sex eq 2 then do;
 color='orange';
 text='R';
end;
group=country; midpoint=sex; y=5; output;
run;


goptions device=png;
goptions hsize=8.5in vsize=5in;
goptions hsize=9.0in vsize=5.25in;
goptions cback=cxCCCC99;
goptions border;

/* Maybe this will hypothetically make the stick-people look better */
goptions fontres=presentation;
 
ODS LISTING CLOSE;
ODS HTML path=odsout body="&name..htm" 
 (title="Life Expectancy comparison, by country") 
 style=htmlblue;
 
goptions ftitle="albany amt/bold" ftext="albany amt" htitle=5 htext=3 gunit=pct;
goptions ctext=gray33;

title1 ls=1.5 "Figure 3-4 Life Expectancy of Selected Nations";

/* Use 'note' rather than title2, so it can it can 'share' the graph space */
*title2 font="albany amt/bold" h=4.5 "Year 2001";

footnote1 h=1 ' ';

/* Get rid of the midpoint axis, since that's redundant with the legend */
axis1 label=none value=none label=none;

axis2 minor=none order=(0 to 100 by 20) label=(f="albany amt/bold" 'Age') noplane;

axis3 label=none value=(f="albany amt/bold") label=none offset=(3,3) noplane split='\';

pattern1 v=solid c=vlig;
pattern2 v=solid c=cornsilk;

legend1 mode=protect position=(top right inside) across=1
 label=none noframe /*cframe=graydd*/ shape=bar(2,2)
 value=(h=3 j=l f="albany amt" 'Male' 'Female')
 offset=(0,-5);

proc gchart data=my_data anno=my_anno; 
format country countries.;
format sex sexes.;
note move=(44,87) font='albany amt/bold' height=5 "Year 2001";
vbar3d sex / discrete type=sum sumvar=age  
 group=country subgroup=sex legend=legend1
 maxis=axis1 raxis=axis2 gaxis=axis3 noframe
 shape=cylinder coutline=gray99 outside=sum
 autoref cref=graydd clipref
 width=3 space=0 gspace=4.0
 html=myhtml
 des='' name="&name"; 
run;

quit;
ODS HTML CLOSE;
ODS LISTING;
