BookmarkSubscribeRSS Feed
tc
Lapis Lazuli | Level 10 tc
Lapis Lazuli | Level 10

Tokyo 2020 Summer Olympic Games - Top 5 Medal-Winning CountriesTokyo 2020 Summer Olympic Games - Top 5 Medal-Winning Countries

 

Inspired by simplexCT's neat How to Create a Flag Chart in Excel (countries winning the most Summer Olympics medals from 1896-2016), here's a SAS ODS Graphics scatter plot with flag markers for the top 5 medal-winning countries at the just-concluded Tokyo 2020 Olympic Games (with a gold-silver-bronze bar chart tossed in for background color!).

 

* Fun with SAS ODS Graphics: Thar's Gold (and Silver and Bronze) in Them Thar Olympics!
  Based on simplexCT's neat Excel Flag Chart simplexct.com/how-to-create-a-flag-chart-in-excel 
  Data, flag icons courtesy of Google google.com/search?q=olympic+medal+count;

data medals;                                               * Read data for top 5 medal-winning countries;
input Rank Country $15.  Gold  Silver  Bronze  Total;
datalines;
1 United States  39  41  33  113
2 China          38  32  18  88
3 Japan          27  14  17  58
4 Great Britain  22  21  22  65
5 ROC            20  28  23  71
;                                                          * Transpose from 1 row per country to 1 row per country/medal;               
proc transpose data=medals out=medalsT(rename=(_name_=Medal col1=Medals)); 
by rank country notsorted;
var Gold  Silver  Bronze  Total;
                                                           * Create temp variables for charting, exclude totals;
proc sql noprint;
create table medalsT2 as 
select m.*, max(medals)+1 as maxmedals, 
       case medal when 'Gold' then 1 when 'Silver' then 2 when 'Bronze' then 3 end as medalnum,
       trim(upcase(country))||' '||compress(put(medals,comma5.)) as countrymedals 
       from medalsT(where=(medal^='Total')) m;
select min(medals)-1 into :minmedals from medalsT2;  
select max(medals)+1 into :maxmedals from medalsT2;       
                                                           * Format medal numbers; 
proc format;
value medal 1='GOLD' 2='SILVER' 3='BRONZE' other=' ';
                                                           * Scatter plot of medals won with country flag markers;
ods graphics / width=8.5in height=8.5in attrpriority=none; * Bar chart used for gold-silver-bronze background;
proc sgplot data=medalsT2 noautolegend nowall noborder;
inset '2020 Olympics' / position=topright textattrs=(size=16pt weight=bold);
styleattrs datasymbols=(US_Flag CH_Flag JP_Flag GB_flag ROC_Flag);   
symbolimage name=US_Flag  image="/home/ted.conway/flags/US_Flag.png"; * Flag icons for top 5 medal-winning countries;
symbolimage name=CH_Flag  image="/home/ted.conway/flags/CH_Flag.png";
symbolimage name=JP_Flag  image="/home/ted.conway/flags/JP_Flag.png";
symbolimage name=GB_Flag  image="/home/ted.conway/flags/GB_Flag.png";
symbolimage name=ROC_Flag image="/home/ted.conway/flags/ROC_Flag.png";
vbarbasic medalnum / response=maxmedals stat=mean barwidth=1 colorresponse=medalnum colormodel=(gold silver cXcd7f32) 
          nooutline baselineattrs=(thickness=0) transparency=.5 baseline=&minmedals dataskin=pressed;
scatter x=medalnum y=medals / group=rank markerattrs=(size=18pt) datalabel=countrymedals datalabelpos=right datalabelattrs=(color=black);
xaxis display=(nolabel noline noticks) type=linear min=.5 max=3.5 offsetmin=0 offsetmax=0 valuesformat=medal.; 
yaxis display=(noline noticks) label="MEDALS" grid ranges=(&minmedals-&maxmedals) offsetmin=0 offsetmax=0;
run;

ChinaChinaGreat BritainGreat BritainJapanJapanRussian Olympic CommitteeRussian Olympic CommitteeUnited StatesUnited States

2 REPLIES 2
Ksharp
Super User

@tc , How about this one ?

It is from Graph Speaking Blog .

data medals;                                           
input Rank Country $15.  Gold  Silver  Bronze  Total;
datalines;
1 United States  39  41  33  113
2 China          38  32  18  88
3 Japan          27  14  17  58
4 Great Britain  22  21  22  65
5 ROC            20  28  23  71
; 
proc transpose data=medals out=want;
by  Rank Country ;
var Gold  Silver  Bronze  Total;
run;
data want;
 set want;
 if _name_='Gold' then order=1;
  else  if _name_='Silver' then order=2;
   else  if _name_='Bronze' then order=3;
    else  order=4;
run;

proc sort data=want;by order;run;
ods graphics/reset=all;
proc sgpanel data=want noautolegend;
title '2020 Olympics';
panelby _NAME_ / layout=panel columns=4 onepanel sort=data  novarname spacing=5;
    styleattrs datacontrastcolors=(gold Silver cXcd7f32  navy );
    dot Country / response=col1 group=_NAME_ 
        nostatlabel markerattrs=(symbol=circlefilled size=20) datalabel;
    rowaxis discreteorder=data display=(nolabel) fitpolicy=none;
    colaxis integer display=(nolabel);
run;

Ksharp_0-1628518234387.png

 

 

 

 

 

tc
Lapis Lazuli | Level 10 tc
Lapis Lazuli | Level 10
Very nice! The SGPANEL approach requires less width (countries need only appear once) and lets one use UNISCALE=ROW to float the x-axis scales for the medal types + totals if desired to increase separation!

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1220 views
  • 10 likes
  • 2 in conversation