%let name=best_beer; filename odsout '.'; /* Based on data from http://lyke2drink.blogspot.com/2008/10/gabf-medals-few-states-and-breweries.html */ proc format; value my_fmt 3='Gold' 2='Silver' 1='Bronze' ; run; data mydata; format medal my_fmt.; input Category $ 1-9 beer_name $ 11-45 medal count; datalines; Beers Alaskan\Smoked Porter 1 5 Beers Alaskan\Smoked Porter 2 4 Beers Alaskan\Smoked Porter 3 6 Beers New Belgium Abbey\Belgian Style Ale 1 4 Beers New Belgium Abbey\Belgian Style Ale 3 6 Beers Genesee Cream Ale 1 3 Beers Genesee Cream Ale 2 5 Beers Genesee Cream Ale 3 2 Beers Samuel Adams\Double Bock 1 3 Beers Samuel Adams\Double Bock 3 6 Beers O'Doul's Amber NA 1 3 Beers O'Doul's Amber NA 2 2 Beers O'Doul's Amber NA 3 3 Beers Laughing Lab Scotish Ale 1 2 Beers Laughing Lab Scotish Ale 2 4 Beers Laughing Lab Scotish Ale 3 2 Beers Miller Genuine Draft 1 1 Beers Miller Genuine Draft 2 6 Beers Miller Genuine Draft 3 1 Beers New Glarus Belgian Red 2 2 Beers New Glarus Belgian Red 3 5 Beers Old Milwaukee Light 1 1 Beers Old Milwaukee Light 2 1 Beers Old Milwaukee Light 3 5 Beers Coors 1 2 Beers Coors 2 3 Beers Coors 3 2 Beers Budweiser 1 3 Beers Budweiser 2 2 Beers Budweiser 3 2 Beers O'Doul's NA 1 2 Beers O'Doul's NA 2 4 Beers O'Doul's NA 3 1 ; run; /* Number the beer names (data order), to use in user-defined format */ data mydata; set mydata; by beer_name notsorted; if first.beer_name then data_order+1; run; proc sql; create table fmt_data as select unique data_order, beer_name from mydata; quit; run; data control; set fmt_data (rename = ( data_order=start beer_name=label)); fmtname = 'beername'; type = 'N'; end = START; run; proc format lib=work cntlin=control; run; /* I annotate the number of medals on the bar segments, so I can make them different colors. Gcharts inside= would only make them 1 color. */ data anno_text; set mydata; length function color $8; xsys='2'; ysys='2'; when='a'; midpoint=data_order; subgroup=medal; function='label'; position='e'; text=trim(left(count)); if medal=1 then color='yellow'; else if medal=2 then color='black'; else if medal=3 then color='brown'; else color='pink'; run; data anno_back; length function $8 style $20; when='b'; xsys='3'; ysys='3'; x=0; y=0; function='move'; output; ysys='1'; x=100; y=0; function='bar'; style='solid'; line=0; color='cx002b2c'; output; xsys='3'; ysys='1'; x=0; y=100; function='move'; output; ysys='3'; x=100; y=100; function='bar'; style='solid'; line=0; color='white'; output; xsys='3'; ysys='1'; x=75; y=100; function='poly'; style='solid'; line=1; color='cx10474a'; output; function='polycont'; x=x+2.6; output; ysys='3'; y=99; x=x+1; output; x=x-1-2.6-1; output; xsys='3'; ysys='1'; x=75+.5; y=100; function='poly'; style='solid'; line=1; color='cx196469'; output; function='polycont'; x=x+2.6-.5-.5; output; ysys='3'; y=99-.5; x=x+1; output; x=x-1-2.6+.5+.5-1; output; run; /* Define a template, to get the graphic behind the map ... */ /* http://pro.corbis.com/images/CB053273.jpg?size=572&uid=%7B898FBA71-1D21-4419-8861-A243E68B2F6C%7D */ ods path work.template(update) sashelp.tmplmst; proc template; define style styles.beer; parent = styles.minimal; style Body from Document / backgroundimage = "woodgrain.jpg" ; end; run; GOPTIONS DEVICE=png; ODS LISTING CLOSE; ODS HTML path=odsout body="&name..htm" (title="America's Top Beers") style=beer; goptions ftitle="arial/bold" ftext="arial/bold" gunit=pct htitle=5.0 htext=2.5; goptions ctext=cxc7dfe1 /* ctext=cx5ca0ab */; goptions cback=cx10474a; /* beer color cx196469 */ axis1 label=none value=none major=none minor=none style=0 offset=(0,8); axis2 label=none split='\' value=(angle=75 height=1.8) offset=(10,6) style=0; legend1 label=none across=1 position=(top right inside) value=(justify=left) order=(3 2 1) shape=bar(.1in,.1in) offset=(-4,-4); pattern1 v=solid c=cxb76f25; pattern2 v=solid c=cxb4b9bf; pattern3 v=solid c=cxedcb2b; title c=cx10474a "America's Top Beers"; footnote h=3 " "; proc gchart data=mydata (where=(category='Beers')) anno=anno_back; /* Descending doesn't sort by the max gold medals, within groups of same total medal count, so I'm using data-order, and a user-defined format calculated from the data. */ format data_order beername.; vbar data_order / discrete type=sum sumvar=count subgroup=medal raxis=axis1 maxis=axis2 noframe cframe=cx10474a coutline=same outside=sum legend=legend1 anno=anno_text des="" name="&name"; run; quit; ODS HTML CLOSE; ODS LISTING;