Way to go Team USA, 28 Olympic medals!

4

I must admit, I’m glad the 2014 Winter Olympics are over. I’ve spent too many night-time hours glued to the TV. I can now get on with my life. But first, let’s have a little SAS fun with the medal standings.

How do you prefer your summary of medal standings - bar chart or data table?

The following vertical bar chart was created with the GCHART procedure and numerous global statements such as AXIS and LEGEND:

The following data table was created with the REPORT procedure and STYLE= options:

If you like what you see, be sure to check out the code at the end of this blog.

SAS Program:

data standings;
  infile datalines dlm=',';
  input Country:$15. _1Gold _2Silver _3Bronze _0Total;
  datalines;
Russian Fed.,13,11,9,33
United States,9,7,12,28
Norway,11,5,10,26
Canada,10,10,5,25
Netherlands,8,7,9,24
Germany,8,6,5,19
Austria,4,8,5,17
France,4,4,7,15
Sweden,2,7,6,15
Switzerland,6,3,2,11
;
run;
 
proc sort data=standings;
  by Country;
run;
 
proc transpose data=standings 
                out=standingsrotated(rename=(col1=Number))
                name=Medal;
  by Country;
  var _1Gold _2Silver _3Bronze;
run; 
 
proc sort data=standings;
  by descending _0Total;
run;
 
ods html path='c:\temp' file='Olympics.html' nogtitle nogfootnote style=sasweb;
 
goptions reset=all colors=(gold silver cxCD7F32) htext=12pt border;
title1 c=black h=14pt 'XXII Olympic Winter Games (Sochi)';
title2 c=black h=12pt 'Medal Counts for Top 10 Countries, Based on Total Count';
footnote1 c=black h=12pt link='http://www.sochi2014.com/en/medal-standings' 
          'Data Source: www.sochi2014.com';
axis1 label=none value=(angle=-45) length=70pct;
axis2 label=(a=90 'Medal Count') length=70pct;
legend1 frame cblock=gray position=(top center inside) mode=protect 
        label=none value=(t=1 'Gold' t=2 'Silver' t=3 'Bronze');
 
proc gchart data=standingsrotated;
  vbar Country / sumvar=Number subgroup=Medal sum
                 maxis=axis1 raxis=axis2 legend=legend1
                 coutline=same;
run;
quit;
 
proc report data=standings nowd
             style(report)={bordercolor=black cellspacing=0 rules=all}
             style(header)={color=black backgroundcolor=white just=right fontsize=12pt}
             style(column)={width=1in fontsize=12pt vjust=middle};
  column Country _1Gold _2Silver _3Bronze _0Total;
  define Country / style(header)={just=left} 
                   style(column)={width=2in};
  define _1Gold / 'Gold' style(header)={backgroundcolor=gold} 
                         style(column)={backgroundcolor=gold};
  define _2Silver / 'Silver' style(header)={backgroundcolor=silver} 
                             style(column)={backgroundcolor=silver};
  define _3Bronze / 'Bronze' style(header)={backgroundcolor=cxCD7F32} 
                             style(column)={backgroundcolor=cxCD7F32};
  define _0Total / 'Total';
  compute Country;
    if Country='United States' then 
       call define(_COL_,'STYLE',
       'style={prehtml="<img src=http://gtcdn.sochi2014.com/flag/large/usa.png width=55 align=middle>"}');
    else if Country='Russian Fed.' then 
       call define(_COL_,'STYLE',
       'style={prehtml="<img src=http://gtcdn.sochi2014.com/flag/large/rus.png width=55 align=middle>"}');
    else if Country='Netherlands' then 
       call define(_COL_,'STYLE',
       'style={prehtml="<img src=http://gtcdn.sochi2014.com/flag/large/ned.png width=55 align=middle>"}');
    else if Country='Norway' then 
       call define(_COL_,'STYLE',
       'style={prehtml="<img src=http://gtcdn.sochi2014.com/flag/large/nor.png width=55 align=middle>"}');
    else if Country='Canada' then 
       call define(_COL_,'STYLE',
       'style={prehtml="<img src=http://gtcdn.sochi2014.com/flag/large/can.png width=55 align=middle>"}');
    else if Country='Germany' then 
       call define(_COL_,'STYLE',
       'style={prehtml="<img src=http://gtcdn.sochi2014.com/flag/large/ger.png width=55 align=middle>"}');
    else if Country='France' then 
       call define(_COL_,'STYLE',
       'style={prehtml="<img src=http://gtcdn.sochi2014.com/flag/large/fra.png width=55 align=middle>"}');
    else if Country='Sweden' then 
       call define(_COL_,'STYLE',
       'style={prehtml="<img src=http://gtcdn.sochi2014.com/flag/large/swe.png width=55 align=middle>"}');
    else if Country='Switzerland' then 
       call define(_COL_,'STYLE',
       'style={prehtml="<img src=http://gtcdn.sochi2014.com/flag/large/sui.png width=55 align=middle>"}');
    else if Country='Austria' then 
       call define(_COL_,'STYLE',
       'style={prehtml="<img src=http://gtcdn.sochi2014.com/flag/large/aut.png width=55 align=middle>"}');
  endcomp;
run;
 
ods html close;
Tags
Share

About Author

Michele Ensor

Michele Ensor is a Senior SAS instructor teaching public, on-site, and Live Web classes. She has been employed as an instructor with SAS since 1997 and has been using SAS since 1993. Michele received a Bachelor of Science in Mechanical Engineering from University of Illinois and a Master of Business Administration from Clemson University.

4 Comments

  1. Pingback: Olympic graphs on steroids! | The SAS Training Post

  2. Thank you for this blog post, Michele. If I wanted to include images for the medals, say, underneath the column headers Gold, Silver, and Bronze, would I be able to do that via the respective DEFINE statement (e.g. define _1Gold) or are additional COMPUTER blocks for each column header necessary? Thank you for any suggestions you can provide.

    • Good thought Daniel! You can add an image to the header using the DEFINE statement plus ODS ESCAPECHAR.

      Before the PROC REPORT step, add a statement like the following:
      ods escapechar='~';
      On the DEFINE statement after the forward slash, add header syntax like the following:
      '~{style [postimage="c:\temp\gold.png"] Gold}'
      Instead of POSTIMAGE, you can use POSTHTML. POSTHTML is a little more syntax but you can control the size of the image.
      '~{style [posthtml=""] Gold}'

      If you have never used ODS ESCAPECHAR, be sure to check out the documentation. Great tool for performing in-line formatting.
      http://support.sas.com/documentation/cdl/en/odsug/65308/HTML/default/viewer.htm#p11xia2ltavr8ln17srq8vn4rnqc.htm

      • Thank you for your response, Michele. I will definitely gives this a try. (And please forgive me the "auto-correct" typo regarding the COMPUTE block. It might have been wishful thinking to get additional "COMPUTER blocks" installed in my office.)

Back to Top