%let name=guns; filename odsout '.'; /* Imitation of graph in April 2000 "American Demographics" magazine, p. 21 */ proc format; value efffmt 1='Very effective' 2='Somewhat effective' 3='Not too/Not at all effective' ; run; data a; format effective efffmt.; input group $ 1-11 effective percent; cards; Male 1 53 Male 2 20 Male 3 24 Female 1 70 Female 2 15 Female 3 13 Republican 1 56 Republican 2 19 Republican 3 24 Democrat 1 65 Democrat 2 17 Democrat 3 16 Independent 1 63 Independent 2 17 Independent 3 17 Parent 1 64 Parent 2 18 Parent 3 16 Non-parent 1 60 Non-parent 2 18 Non-parent 3 20 ; run; /* Add chart tip variable... */ data a; set a; length htmlvar $500; htmlvar='title='||quote( 'Group: '|| trim(left(Group)) ||'0D'x|| 'Effectiveness: '|| trim(left(put(effective,efffmt.))) ||'0D'x|| 'Percent: '|| trim(left(percent))||'%' ) ||' '|| 'href="infect.htm"'; run; /* Sort the data, so you can use 'by group' in the next data step, so you can use the 'first.group' stuff. */ proc sort data=a out=a; by group effective percent; run; data bar_anno; set a; by group; if first.group then do; cumpct=percent; end; else do; cumpct+percent; end; run; data bar_anno; set bar_anno; by group; lag=lag(cumpct); if first.group then do; x=percent/2; end; else do; x=(percent/2)+lag; end; run; run; data bar_anno; set bar_anno; hsys='3'; when='a'; function='label'; position='5'; xsys = '2'; ysys = '2'; style='"arial/bo"'; size=3.5; midpoint=group; pct=percent/100; text =trim(left(put(pct,percent5.0))); cbox='black'; /* cborder='white'; */ color='white'; output; run; /* Annotated background colors - black at top, and gradient in lower sections */ data anno_colors; length function style color $10; retain xsys '3' ysys '3' when 'b' style 'solid'; /* Annotate a black bar in the top/title quadrant of the screen */ function='move'; x=0; y=89; output; function='bar'; x=100; y=100; color='black'; output; /* Now, annotate lines of incrementing gradient shading, from light blue to mild/darker blue, from the top to the bottom */ orig_red= input('72',hex2.); orig_green=input('8f',hex2.); orig_blue= input('ce',hex2.); do i=0 to 89 by 1; count+1; function='move'; x=0; y=i; output; function='bar'; x=100; y=i-1; percent=(count-1)/(90); red=orig_red + ( (256-orig_red) * percent ); green=orig_green + ( (256-orig_green) * percent ); blue=orig_blue + ( (256-orig_blue) * percent ); rgb=put(red,hex2.)||put(green,hex2.)||put(blue,hex2.); color="cx"||rgb; output; end; run; GOPTIONS DEVICE=gif; ODS LISTING CLOSE; ODS HTML path=odsout body="&name..htm" style=minimal gtitle gfootnote ; goptions border; goptions hsize=6in vsize=5in; goptions gunit=pct htitle=4 htext=3 ftitle="arial/bold" ftext="arial/bold"; goptions cback=graycc; title1 h=1.5 " "; title2 h=3.5 f="arial/bo" c=white "WOMEN AND DEMOCRATS ARE MORE SUPPORTIVE"; title3 h=3.5 f="arial/bo" c=white "OF GUN CONTROLS THAN MEN AND REPUBLICANS"; title4 h=3.0 " "; title5 h=2.5 j=c c=black "Question: " c=cxc22817 "How effective are stricter gun control laws as a way to stop violence in schools?"; title6 a=90 h=4 " "; title7 a=-90 h=4 " "; footnote1 j=r h=3.5pct f="arial/bold/it" "Source: Gallup Organization / CNN / USA Today, 4/99 "; footnote2 j=r f="arial" c=graydd "(data in this example not exact - estimated from graph in magazine) "; pattern1 color=cxc22817 value=solid; pattern2 color=orange value=solid; pattern3 color=green value=solid; /* Use a special axis statement to get the bars in the exact order desired */ axis1 label=none value=(justify=right) order=( 'Male' 'Female' 'Republican' 'Democrat' 'Independent' 'Parent' 'Non-parent' ) ; axis2 order=(0 to 100 by 20) label=none minor=none major=(height=-.5 cells); legend1 label=none shape=bar(.1in,.1in) frame cframe=white cborder=black across=3 value=(h=2.5 justify=left); proc gchart data=a anno=anno_colors; hbar group / discrete nostats sumvar=percent subgroup=effective anno=bar_anno maxis=axis1 raxis=axis2 legend=legend1 coutline=black noframe html=htmlvar des="" name="&name"; run; quit; ODS HTML CLOSE; ODS LISTING;