After seeing Ferdio's creative "1 dataset 100 visualizations" project, what was I supposed to do - NOT try to knockoff one of them using SAS ODS Graphics? 😀 Code below (results above) inspired by Viz #41, a dot plot of a simple World Heritage Sites dataset.
* Fun With SAS ODS Graphics: Attempt to knockoff Viz #41 (World Heritage Sites dot plot) from Ferdio's creative "1 dataset 100 visualizations" project
Inspired by 100.datavizproject.com/data-type/viz41 100.datavizproject.com from ferdio.com;
data viz41; * Get 2004+2022 World Heritage Sites data for Norway, Denmark, Sweden;
array countries{*} $ country1-country3; * Array to hold 3 countries and # sites for reshaping;
array sites{*} sites1-sites3;
input title $80.; * Get description of data;
input country1-country3; * Grab 3 country names;
do row=1 to 2; * Read rows with data for 2004 and 2022;
input yr sites1-sites3;
do col=1 to 3; * And for each year/country...;
country=countries{col};
do y=1 to sites{col}; output; end; * ...output one observation ("dot") for of its N sites for dot plot;
end;
end; * Inline data from 100.datavizproject.com follows;
datalines;
Number of World Heritage Sites
Norway Denmark Sweden
2004 5 4 13
2022 8 10 15
;
proc sort; by yr country; * Sort data in ascending order by year/country;
proc format; * Country names + abbreviations;
value $countryF "Denmark"="DK" "Norway"="NO" "Sweden"="SE";
proc sgpanel data=viz41 noautolegend pad=48pt; * Make a "dot strip" scatter plot;
panelby yr / onepanel layout=columnlattice columns=2 colheaderpos=bottom Headerattrs=(weight=bold) noborder nowall headerbackcolor=white noheaderborder novarname;
styleattrs datacontrastcolors=(red black blue); * Contrasting colors for each country;
scatter x=country y=y / group=country markerattrs=(symbol=circlefilled size=14pt); * Plot one "dot" per site;
colaxis display=(noticks noline nolabel) offsetmin=.25 offsetmax=.25;
rowaxis display=none offsetmin=.05 offsetmax=.05;
format country $countryF.; * Print country abbreviation instead of full name;
run;
With respect, I don't think this is a good visualization that is worthy of being reproduced. With no vertical axis, we are forced to count the number of dots if we want to know the number of sites in each country.
It seems like a simple bar chart is an easier and more effective presentation of these data. No doubt this is one of the "100 visualizations" that are considered.
You transposed the data from wide to long in the DATA step. I decided to use PROC TRANSPOSE, but either will work.
data sites;
input Year Norway Denmark Sweden;
datalines;
2004 5 4 13
2022 8 10 15
;
/* Transpose the variables from wide to long format */
proc transpose data=sites
out=long(rename=(Col1=NumSites)) name=Country;
by Year; /* for each subject */
var Norway Denmark Sweden; /* make a row for these variables */
run;
title "World Heritage Sites in Scandinavia";
proc sgplot data=long;
vbar Year / response=NumSites group=Country groupdisplay=cluster;
label NumSites="Number of World Heritage Sites"
Country="Country";
xaxis display=(nolabel);
yaxis integer grid;
run;
With respect, I don't think this is a good visualization that is worthy of being reproduced. With no vertical axis, we are forced to count the number of dots if we want to know the number of sites in each country.
It seems like a simple bar chart is an easier and more effective presentation of these data. No doubt this is one of the "100 visualizations" that are considered.
You transposed the data from wide to long in the DATA step. I decided to use PROC TRANSPOSE, but either will work.
data sites;
input Year Norway Denmark Sweden;
datalines;
2004 5 4 13
2022 8 10 15
;
/* Transpose the variables from wide to long format */
proc transpose data=sites
out=long(rename=(Col1=NumSites)) name=Country;
by Year; /* for each subject */
var Norway Denmark Sweden; /* make a row for these variables */
run;
title "World Heritage Sites in Scandinavia";
proc sgplot data=long;
vbar Year / response=NumSites group=Country groupdisplay=cluster;
label NumSites="Number of World Heritage Sites"
Country="Country";
xaxis display=(nolabel);
yaxis integer grid;
run;
@Rick_SAS: Good suggestions + observations, as always. Yes, Ferdio did include some more fully-labeled bar charts in their 100-data-visualizions-on-the-wall compilation and issued a caveat suggesting Viz #41 was more about design whimsy than practicality ("A dot plot or dot chart visualizing the exact number of World Heritage sites for each year and country. No axis or labels used for simplicity, so the numbers will have to be counted manually.").
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.
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.
Ready to level-up your skills? Choose your own adventure.