Data visualization with SAS programming

Is there a way to Reverse Geocode? Take Lat/Long and convert to an address?

Reply
N/A
Posts: 1

Is there a way to Reverse Geocode? Take Lat/Long and convert to an address?

Is there a way to take a set of latitude and longitude coordinates and reverse geocode them to get an address?

Super User
Posts: 19,772

Re: Is there a way to Reverse Geocode? Take Lat/Long and convert to an address?

I don't know if SAS can do it, but there are tools online that can do it:

geocoder.ca: geocoding for North America - USA and Canada

You could probably write an algorithm to pass data to the service via the API - $1 per 400 lookups appears to be the rate.

Probably need to investigate the TOS.

SAS Employee
Posts: 170

Re: Is there a way to Reverse Geocode? Take Lat/Long and convert to an address?

SAS cannot do Reverse Geocoding.

There are some commercial places but there are a few free ones.  I can't say how good they are.  You might Google "Reverse Geocoding".  A few more that show up are:

Free Online Reverse Geocoding

GeoNames reverse address geocoding

Trusted Advisor
Posts: 1,301

Re: Is there a way to Reverse Geocode? Take Lat/Long and convert to an address?

Posted in reply to Darrell_sas
SAS Employee
Posts: 170

Re: Is there a way to Reverse Geocode? Take Lat/Long and convert to an address?

Google prohibits using a service (such as geocoding) without displaying the contents/results on a Google Map.  See 10.1.1.h of the Google Maps Terms of Use:

https://developers.google.com/maps/terms

https://developers.google.com/maps/terms

Trusted Advisor
Posts: 1,301

Re: Is there a way to Reverse Geocode? Take Lat/Long and convert to an address?

Posted in reply to Darrell_sas

A very important note

A direct link:

Google Maps/Google Earth APIs Terms of Service

New Contributor
Posts: 2

Re: Is there a way to Reverse Geocode? Take Lat/Long and convert to an address?

After much research I landed on a service by TA&M University. You can process batches. I assume this is why you are looking for a SAS solution:

 

http://geoservices.tamu.edu/Services/Geocode/

 

Please let us know if you found a SAS solution. Thanks.

SAS Employee
Posts: 982

Re: Is there a way to Reverse Geocode? Take Lat/Long and convert to an address?

Do you need to find the closest street address? ... or would the closest city or zipcode be good enough?

(if the closest city or zipcode is good enough, then I could write some SAS code to do that)

New Contributor
Posts: 2

Re: Is there a way to Reverse Geocode? Take Lat/Long and convert to an address?

Posted in reply to RobertAllison_SAS
Zip Code is fine.
SAS Employee
Posts: 982

Re: Is there a way to Reverse Geocode? Take Lat/Long and convert to an address?

Ok - then here's a way to do that, using brute force (and the sashelp.zipcode dataset).

You might refine this to make it a little less code, and more efficient - but I like to take things 1 step at a time, to make it simpler to understand. :-)

 

 

data foo;
input customer_number lat long;
datalines;
1 35.8227817 -78.755733
2 38.8976398 -77.036627
;
run;

 

/* Create all possible pairs of my data, and zipcode lat/longs */
proc sql;
create table pairs as
select unique foo.*, zipcode.zip, zipcode.city, zipcode.x, zipcode.y
from foo, sashelp.zipcode
where zipcode.x^=. and zipcode.y^=.;
quit; run;

 

/* calculate distance between each customer and each zipcode centroid */
data pairs; set pairs;
Distance = geodist(lat, long, y, x, 'DM');
run;

 

/* find the closest zipcode to each customer */
proc sort data=pairs out=pairs;
by customer_number distance;
run;
data pairs; set pairs (keep = customer_number lat long zip city);
by customer_number;
label zip='Closest Zipcode';
if first.customer_number then output;
run;

 

results.png

 

Ask a Question
Discussion stats
  • 9 replies
  • 1217 views
  • 10 likes
  • 6 in conversation