libname data 'C:\'; %let gpath=C:\; %let dpi=200; proc sort data=data.sochi out=sochi; by descending gold; run; /**/ data sochi; set sochi; Total=gold+silver+bronze; run; /*ods html;*/ /*proc print noobs;run;*/ /*ods html close;*/ data sochi_group; length Medal $6; set sochi; keep rank country medal count; Medal='Gold'; Count=gold; output; Medal='Silver'; Count=silver; output; Medal='Bronze'; Count=bronze; output; Medal='Total'; Count=gold+silver+bronze; output; run; /*ods html;*/ /*proc print noobs;run;*/ /*ods html close;*/ /*--Medal Class Panel--*/ ods listing gpath="&gpath" image_dpi=&dpi; ods graphics / reset width=6in height=4in imagename='Sochi_Medal_Lattice'; proc sgpanel data=sochi_group ; title 'Sochi Medals Counts by Country Ordered by Gold Medals'; panelby medal / layout=panel columns=4 onepanel sort=data novarname spacing=5; styleattrs datacontrastcolors=(gold silver %rgbhex(236, 143, 44) black); dot country / response=count group=medal markerattrs=(symbol=circlefilled size=10) nostatlabel; rowaxis discreteorder=data display=(nolabel) fitpolicy=none; colaxis integer display=(nolabel); run; data sochi_group_H; length Medal $6; set sochi; keep rank country medal count total HasGold count_m Low; HasGold=ifc(gold>0, 'Yes', 'No'); Low=0; Medal='Bronze'; Count=ifn(bronze>0,bronze,.); Count_m=Count+0.5; Total=total; output; Medal='Silver'; Count=ifn(silver>0,silver,.); Count_m=Count+0.5; Total=.; output; Medal='Gold'; Count=ifn(gold>0,gold,.); Count_m=Count+0.5; Total=.; output; run; /*ods html;*/ /*proc print noobs;*/ /* var rank country medal count total hasgold count_m Low;*/ /*run;*/ /*ods html close;*/ data sochi_group_V; length Medal $6; set sochi; keep rank country medal count total HasGold count_m; HasGold=ifc(gold>0, 'Yes', 'No'); Medal='Gold'; Count=ifn(gold>0,gold,.); Count_m=Count+0.5; Total=total; output; Medal='Silver'; Count=ifn(silver>0,silver,.); Count_m=Count+0.5; Total=.; output; Medal='Bronze'; Count=ifn(bronze>0,bronze,.); Count_m=Count+0.5; Total=.; output; run; /*ods html;*/ /*proc print noobs;*/ /* var rank country medal count total hasgold count_m;*/ /*run;*/ /*ods html close;*/ /*--Macro by Perry Watts--*/ %macro RGBHex(rr,gg,bb); %sysfunc(compress(CX%sysfunc(putn(&rr,hex2.)) %sysfunc(putn(&gg,hex2.)) %sysfunc(putn(&bb,hex2.)))) %mend RGBHex; ods listing gpath="&gpath" image_dpi=&dpi; ods graphics / reset width=4in height=6in imagename='Sochi_H'; proc sgplot data=sochi_group_H(where=(Hasgold='Yes')) nocycleattrs; title 'Sochi Medals by Country'; footnote j=l 'For countries with at least one Gold'; symbolimage name=gold image='C:\Work\Blogs\Graphically Speaking\2014\Post_Feb_16_Sochi\Gold_Trans_2.png'; symbolimage name=silver image='C:\Work\Blogs\Graphically Speaking\2014\Post_Feb_16_Sochi\Silver_Trans_2.png'; symbolimage name=bronze image='C:\Work\Blogs\Graphically Speaking\2014\Post_Feb_16_Sochi\Bronze_Trans_2.png'; styleattrs datacolors=( %rgbhex(236, 143, 44) silver gold ) datacontrastcolors=(black black black) datasymbols=(bronze silver gold ); hbarparm category=country response=total / fillattrs=(color=gray transparency=0.8) nooutline name='b' legendlabel='Total' datalabel=total dataskin=sheen; hbarparm category=country response=count / group=medal dataskin=sheen outlineattrs=(color=black) name='a'; scatter y=country x=count_m / group=medal groupdisplay=cluster markerattrs=(size=20); keylegend 'a' 'b' / location=inside position=bottomright across=1; xaxis display=(nolabel) grid integer values=(0 to 12 by 2) offsetmin=0; yaxis discreteorder=data display=(nolabel); run; ods listing gpath="&gpath" image_dpi=&dpi; ods graphics / reset width=4in height=6in imagename='Sochi_H_Needle'; proc sgplot data=sochi_group_H(where=(Hasgold='Yes')) nocycleattrs; title 'Sochi Medals by Country'; footnote j=l 'For countries with at least one Gold'; symbolimage name=gold image='C:\Work\Blogs\Graphically Speaking\2014\Post_Feb_16_Sochi\Gold_Trans_2.png'; symbolimage name=silver image='C:\Work\Blogs\Graphically Speaking\2014\Post_Feb_16_Sochi\Silver_Trans_2.png'; symbolimage name=bronze image='C:\Work\Blogs\Graphically Speaking\2014\Post_Feb_16_Sochi\Bronze_Trans_2.png'; styleattrs datacolors=( %rgbhex(236, 143, 44) silver gold ) datacontrastcolors=(black black black) datasymbols=(bronze silver gold ); hbarparm category=country response=total / fillattrs=(color=gray transparency=0.8) nooutline name='b' legendlabel='Total' datalabel=total dataskin=sheen; hbarparm category=country response=count / group=medal dataskin=sheen outlineattrs=(color=black) barwidth=0.3 name='a'; scatter y=country x=count / group=medal groupdisplay=cluster markerattrs=(size=20); keylegend 'a' 'b' / location=inside position=bottomright across=1; xaxis display=(nolabel) grid integer values=(0 to 12 by 2) offsetmin=0; yaxis discreteorder=data display=(nolabel); run; ods graphics / reset width=6in height=4in imagename='Sochi_V'; proc sgplot data=sochi_group_V(where=(Hasgold='Yes')) nocycleattrs; title 'Medals by Country'; symbolimage name=gold image='C:\Work\Blogs\Graphically Speaking\2014\Post_Feb_16_Sochi\Gold_Trans_2.png'; symbolimage name=silver image='C:\Work\Blogs\Graphically Speaking\2014\Post_Feb_16_Sochi\Silver_Trans_2.png'; symbolimage name=bronze image='C:\Work\Blogs\Graphically Speaking\2014\Post_Feb_16_Sochi\Bronze_Trans_2.png'; styleattrs datacolors=(gold silver %rgbhex(236, 143, 44) ) datacontrastcolors=(black black black) datasymbols=(gold silver bronze); vbarparm category=country response=total / fillattrs=(color=gray) nooutline transparency=0.8 name='b' legendlabel='Total'; vbarparm category=country response=count / group=medal dataskin=sheen outlineattrs=(color=black) name='a'; scatter x=country y=count_m / group=medal groupdisplay=cluster markerattrs=(size=20); keylegend 'a' 'b' / location=inside position=topright;; xaxis discreteorder=data display=(nolabel) ; yaxis grid display=(nolabel) integer values=(0 to 12 by 2); run; data sochiTable; set sochi; goldLbl=ifc(gold>0,'Gold', ''); silverLbl=ifc(silver>0,'Silver', ''); bronzeLbl=ifc(bronze>0,'Bronze', ''); run; /*proc print;run;*/ /*--Medal Table--*/ proc template; define statgraph SochiMedalTable; begingraph / datasymbols=(gold silver bronze); symbolimage name=gold image='C:\Work\Blogs\Graphically Speaking\2014\Post_Feb_16_Sochi\Gold_Trans_2.png'; symbolimage name=silver image='C:\Work\Blogs\Graphically Speaking\2014\Post_Feb_16_Sochi\Silver_Trans_2.png'; symbolimage name=bronze image='C:\Work\Blogs\Graphically Speaking\2014\Post_Feb_16_Sochi\Bronze_Trans_2.png'; layout lattice / columns=2 rowdatarange=union border=false columngutter=0 columnweights=(0.6 0.4); sidebar / align=top; layout gridded / rows=2; entry textattrs=graphtitletext 'Sochi Medals by Country Ordered by Golds'; entry textattrs=graphtitletext ' '; endlayout; endsidebar; rowaxes; rowaxis / discreteopts=(colorbands=even colorbandsattrs=(transparency=0.7)) display=(tickvalues) reverse=true; endrowaxes; layout overlay / walldisplay=none x2axisopts=(display=(tickvalues) griddisplay=on linearopts=(tickvaluesequence=(start=0 end=12 increment=2))); barchart category=country response=total / xaxis=x2 orient=horizontal dataskin=sheen barlabel=true name='a' baselineattrs=(thickness=0); endlayout; layout overlay / walldisplay=none x2axisopts=(display=(tickvalues) offsetmin=0.12 offsetmax=0.12); scatterplot y=country x=goldLbl / xaxis=x2 markerattrs=(symbol=gold size=35) name='g'; scatterplot y=country x=silverLbl / xaxis=x2 markerattrs=(symbol=silver size=35) name='s'; scatterplot y=country x=bronzeLbl / xaxis=x2 markerattrs=(symbol=bronze size=35) name='b'; scatterplot y=country x=goldLbl / xaxis=x2 markercharacter=gold labelstrip=true markercharacterattrs=(size=10 color=white weight=bold) outlinedmarkercharacters=true; scatterplot y=country x=silverLbl / xaxis=x2 markercharacter=silver labelstrip=true markercharacterattrs=(size=10 color=white weight=bold) outlinedmarkercharacters=true; scatterplot y=country x=bronzeLbl / xaxis=x2 markercharacter=bronze labelstrip=true markercharacterattrs=(size=10 color=white weight=bold) outlinedmarkercharacters=true; endlayout; endlayout; endgraph; end; run; ods listing gpath="&gpath" image_dpi=&dpi; ods graphics / reset width=5in height=7in imagename='Sochi_Medal_Table'; proc sgrender data=sochiTable template=SochiMedalTable; format gold silver bronze 2.0; run;