Way to go Team USA, 28 Olympic medals!


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;
Russian Fed.,13,11,9,33
United States,9,7,12,28
proc sort data=standings;
  by Country;
proc transpose data=standings 
  by Country;
  var _1Gold _2Silver _3Bronze;
proc sort data=standings;
  by descending _0Total;
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
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} 
  define _1Gold / 'Gold' style(header)={backgroundcolor=gold} 
  define _2Silver / 'Silver' style(header)={backgroundcolor=silver} 
  define _3Bronze / 'Bronze' style(header)={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>"}');
ods html close;

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.


  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.

      • 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.)

Leave A Reply

Back to Top