BookmarkSubscribeRSS Feed

Going for Gold: Visualizing Olympic Medal Counts with SAS Viya

Started ‎03-20-2026 by
Modified ‎03-20-2026 by
Views 350

As a (very) amateur skier, I spent a lot of time last month watching the winter Olympics in Milan and seeing athletes do flips and twists that I had never even realized were possible. Now that the Olympics are all wrapped up, it’s my time to shine instead – but instead of quad axels and gold medals, I’ll use tables and graphs to break down medal distribution across countries. In this article, I’ll walk through an entire data science pipeline using SAS Viya, from accessing web data using Python, to creating maps with PROC SGMAP.

 

Scraping HTML using Python

 

The first thing I need to do is find a data source. I’ll use the 2026 Winter Olympics medal table Wikipedia page, which looks like this:

 

treiman_olympics_1_v2.png

 

I need to scrape this HTML table and convert it to a SAS data set. Luckily, I can use the read_html() function from the Pandas library in Python to do this in one simple step, since SAS supports Python programming directly from SAS Studio or Visual Studio Code.

 

You can find all of the code used in the post here.

 

...
import requests
import pandas as pd
import saspy
sas=saspy.SASsession()

url = "https://en.wikipedia.org/wiki/2026_Winter_Olympics_medal_table"

# Add a browser-like user agent to avoid 403
headers = {
    "User-Agent": (
        "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
        "AppleWebKit/537.36 (KHTML, like Gecko) "
        "Chrome/119.0.0.0 Safari/537.36"
    )
}

# Fetch page with headers
response = requests.get(url, headers=headers)
response.raise_for_status()

# Pandas reads the HTML from the response content
tables = pd.read_html(response.text)

# The medal table is the first table
df = tables[2]

print(df)

# Send to SASUSER library as SASUSER.MEDALS
sas.df2sd(df, table='medals', libref='sasuser')
print("SASUSER.MEDALS created successfully.")
...

 

Note that if you are following along, the read_html() function requires the lxml library to process HTML, which you may need to have installed in your environment.

 

This scrapes the HTML table and creates a new table called MEDALS in the SASUSER library:

 

treiman_olympics_2.png

 

Cleaning the Data

 

However, the new table from Wikipedia isn’t quite ready to use yet. There are a few rows that will cause problems when I try to visualize them, such as a Totals row and the Individual Neutral Athletes row. There are also some quirks: Italy is written as Italy*. Finally, in order to create a map, I need to assign a standard ID key to join it with my existing map data. I’ll use the ISO two-character country code for this.

 

data work.medal_clean;
    set sasuser.medals;
    if index(upcase(NOC), 'TOTALS') then delete;
    if NOC =: 'Individual Neutral' then delete;
    NOC = compress(NOC, '*');
    select (strip(NOC));
        when ('Norway')                 ISO2='NO';
        when ('United States')          ISO2='US';
        …
        otherwise ISO2='';
    end;
run;

*Sort the data by number of gold medals;
proc sort data=work.medal_clean out=medal_clean;
    by descending gold;
run;

 

Visualizing Medal Counts

 

Now that the data is cleaned and ready to go, the last step is to visualize it. I’ll create a map using PROC SGMAP and a bar chart using PROC SGPLOT. SAS comes with a number of map data sets already available in the MAPSGFK library, so creating a choropleth map is as simple as identifying which one you need. In this case, I want to create a world map, so I’ll use the MAPSGFK.WORLD table.

 

title "Total Medals: Milan Cortina 2026";
proc sgmap mapdata=mapsgfk.world
           maprespdata=work.medal_clean;
        choromap total / mapid=id id=iso2 colormodel=(white grey);
run;
title;

proc sgplot data=work.medal_clean(obs=10);
    hbar noc / response=gold
               datalabel
               fillattrs=(color=gold);
    yaxis label="Nation" discreteorder=data;
    xaxis label="Gold Medals";
    title "Top 10 Nations - Gold Medals, 2026 Winter Olympics";
run;

 

The result is a map:

 

treiman_olympics_3.png

 

 

And a bar chart:

 

treiman_olympics_4.png

 

 

Conclusion

 

It turns out that scraping medal tables is much easier than actually winning one—who knew? Luckily, SAS is far more forgiving than a panel of Olympic judges, so even a few missteps along the way won’t cost us any points.

 

By combining Python for data collection and SAS procedures for cleaning and visualization, we’re able to move from raw HTML to polished insights in just a few steps, all on the SAS Viya platform. This same workflow applies to countless real‑world scenarios where data lives online and needs to be transformed quickly into something meaningful. And while the athletes are training for 2030, we can keep exploring new ways to turn raw data into gold‑medal‑worthy analytics using SAS.  

Comments

This graph would be better for Olympic medal count.

https://blogs.sas.com/content/graphicallyspeaking/2014/02/12/sochi-medal-graphs/

Contributors
Version history
Last update:
‎03-20-2026 04:29 PM
Updated by:

Catch up on SAS Innovate 2026

Dive into keynotes, announcements and breakthroughs on demand.

Explore Now →

SAS AI and Machine Learning Courses

The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.

Get started

Article Tags