➤ DISCLOSURE!
It is easy to claim a spot on Google Map when you know geographical coordinates of that location such as latitude and longitude. In my prior posts on the topic of using Google Maps with SAS, knowing the latitudes and longitudes of location was a requirement.
However, what if your data source does not contain those “pesky” latitude and longitude coordinates, but rather only good old postal addresses? Can you still get on Google map?
Handpicked Related Content: The power of SAS-generated InfoWindows in Google maps
The answer is: yes, you can place your location on Google Map using just postal address.
The solution is just one SAS proc away.
Here is an interactive example of several gas stations in the DC area that I placed on a Google map by their address only. Please take a minute to explore this interactive demo before reading further. Make sure to click on Google map markers to display additional information.
What is Geocoding?
Geocoding (sometimes called forward geocoding) is a function of converting a location’s description, such as place name or postal address, into geographic coordinates such as latitude and longitude. Reverse geocoding converts geographic coordinates – latitude and longitude - to a location’s description, usually a postal address or place name.
SAS’ geocoding procedure (yes, you guessed it, PROC GEOCODE ) produces geographic coordinate information for the following entities:
- street addresses
- cities
- U.S. ZIP codes and ZIP+4 extension codes
- foreign postal codes
The geographic coordinates typically represent the center of a ZIP code, a city or an address. So even if you don’t have compete postal address for your location, PROC GEOCODE will produce geographic coordinates for a center of a city or ZIP code.
In order to use street address to generate geographic coordinates, you must specify METHOD=STREET option for PROC GEOCODE (default METHOD is ZIP). Please note, that this method requires rather large lookup datasets which do not automatically installed with your SAS GRAPH software. For more information on the STREET geocoding method and to download necessary lookup data, see Understanding Street Geocoding.
How it is done
1. I downloaded the US street-level file StreetLookupData_94-2014.zip from the SAS Maps Online web page, unzipped it and imported the downloaded .csv files into SAS data tables using the SAS code that came with the zipped file. That SAS tables are used by the PROC GEOCODE as lookup tables.
2. I created an initial data table with addresses for some gas station locations without latitude and longitude information. For simplicity, I used standard default variable names (address, city, state, zip) for locations so I didn’t have to specify them in the proc geocode optional arguments:
3. Ran the following PROC GEOCODE:
/* Street lookup data library */
libname streetdl 'C:\PROJECTS\_BLOG_SAS\geocoding\StreetLookupData_94-2014\sasdata';
/* get geographic coordinates, Y=latitude, X=longitude */
proc geocode
data = work.org_initial_info
out = work.org_info_geocoded
method = street
lookupstreet =streetdl.usm
;
run;
The output dataset org_info_ geocoded includes all the columns from the initial dataset org_initial_info plus the following additional columns (X is a longitude, Y is a latitude):
At this point, our goal of placing multiple location on Google map is covered by my earlier blog post Live Google maps in SAS -- multiple markers. However, here I improved it a bit by using custom markers instead of generic ones. In order to do this, I created small marker images out of the companies’ logos with a transparent background. I saved these small images in the /images folder (relative to the final .html file location) and gave them names corresponding the company names with .png extension. Alternatively, I could have used additional column in the initial data table to specify marker file name.
To specify custom markers, you would need to add just one extra line ('icon: "images/' orgname +(-1) '.png",') in the marker definition, as shown below in the put statement code excerpt:
'var marker' i '= new google.maps.Marker({' /
'position: point' i ',' /
'map: map,' /
'icon: "images/' orgname +(-1) '.png",' /
'title: "Click here for details"' /
'});' /
Click to view and download the full sample SAS code that include all the steps from creating an initial data table without geographic coordinates - latitude and longitude, proc geocode, determining coordinates of the map center, and generating an interactive Google map with custom markers.
Handpicked Related Content: The power of SAS-generated InfoWindows in Google maps
8 Comments
How fun. I knew someone had a database of all the addresses in the U.S., but I didn't know SAS had them. Very nice.
Do we have a database of elevations? I know we can find them online, but maybe there's some PROC ELEVATION that I haven't yet learned. 🙂
Hi John,
Thank you for your feedback. I am not sure if there is a SAS data set that has elevations of individual addresses, but there is a data set MAPSGFK.USCITY that has the altitude of cities. Take a look at this Alternate U.S. City Lookup Data. This data set MAPSGFK.USCITY is provided with SAS/GRAPH and it has 150,000+ US cities listed with their latitude, longitude as well as Altitude in meters (ALT_M) and Altitude in feet (ALT_FT) variables. Hope this helps.
Best regards,
Leonid
Cool ... going to share this information in an upcoming presentation!
Great! I am glad you found it useful.
Neat! And also excited to see Australian post code geocoding is possible with the .zip file available on the SAS Maps Online web page - http://support.sas.com/rnd/datavisualization/mapsonline/html/geocode.html
Pity there is no Australian postal address geocoding possible. However all is not lost as its pretty easy to use google to do the geocoding using the googlemaps api(something its very good at as well).
Richard, you are correct that currently no Australian postal address geocoding lookup file is available for download. However, free Australia Post postcode boundaries are available from the Australian Bureau of Statistics (ABS) in their Postal Areas (POA) file - take a look at this link http://support.sas.com/rnd/datavisualization/mapsonline/html/geocode.html. You are also correct that there is Google geocoding available via their Google Map API.
Hi Michelle,
It was nice meeting you at SAS Global Forum in Orlando earlier this month.
Have you ever had a chance to use Australian post code geocoding?
Best regards,
~Leonid