Have you ever had one of those moments when something you had assumed was true all your life, turned out not to be true? I remember that happening in my high school Spanish class (taught by the wonderful Señor Shoaf), when he let us in on a little secret - the names that we call countries are not always the same as what they call themselves. For example, people in Spain call their country España. My mind was immediately blown, and my world view became a whole lot bigger!
Therefore when I saw the following map on Reddit, it caught my attention and brought back great memories from that high school moment.
It was an interesting map, but I had a few ideas for enhancements. What about adding mouse-over text with the English version of the country names. And what letting the user click on the country to hear the name pronounced!
Getting The Real Country Names
How do I write SAS code to handle these special characters in a map? Well, there are probably several ways to do this, but I chose brute force, with numeric hex codes, and Unicode.
For the country names with special characters, I first looked them up in Wikipedia, where I could copy-n-paste the special characters (since I couldn't copy-n-paste them from the map jpg image in Reddit). Here's an example of Russia, with the real name highlighted and ready to copy-n-paste:
I then copy-n-pasted the name into a web page that would tell me the hex codes for the Unicode characters.
Next, I saved the hex codes in my SAS program like this. Notice that SAS needs 4 hex digits per character, therefore I pad 0's on the left where needed (for example '420' from the table above becomes '0420' in my SAS code below):
I then use the following code to annotate the country name text on the map, in SAS/Graph. Notice I specify '/unicode' after the font name.
And here is what my map looks like, with the country names annotated:
Making the Map Interactive
And now, what about those extra features I wanted to add, to make my map more functional than the one in Reddit? ... How do I get the computer to pronounce the country names? First I copy-n-paste the country name into the forvo page's search box. This takes me to a page that provides one (or more) pronunciations, where I can click the 'play' button to hear them.
I then copy-n-paste the url (from the above page), and save it in a pronunciation_link variable in my SAS annotate dataset. I also add a country_us variable showing what we call the country in the US (in this case, 'Russia').
Now that I have the desired drill-down (pronunciation_link), and mouse-over text (country_us), all I have to do is encode them with the appropriate HTML tags (title= and href=) in a variable called 'html'.
Now, when I hover my mouse over Russia, it has mouse-over text that shows me what we call it in English (Russia), and when you click on it, it drills-down to the page with the pronunciation(s). Click here (or click my map above) to see the interactive version, with the mouse-over text and drill-downs to the pronunciations.
Hopefully you've learned some tricks to help annotate special characters in your SAS/Graphs, and hopefully you'll enjoy seeing (and hearing!) the real country names in my map! Here is a link to my complete SAS code, if you'd like to see all the details, and experiment with it.
Just for Fun
If you made it this far, you now deserve a little fun! Here's a photo my friend Mark took during one of his motorcycle trips around Europe. Can you use my map, and find this country name, and mouse-over the country to see the English name? If you figure out which country it is, leave your answer in a comment below!