SAS to the rescue: claiming your location on Google map by address only (without knowing latitude and longitude)

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:

Table 1. Source Data (org_initial_info SAS dataset)

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):

Table 2. Geocoded Data (org_info_geocoded SAS dataset)

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

SAS to the rescue: claiming your location on Google map by address only (without knowing latitude and longitude) was published on SAS Users.