BookmarkSubscribeRSS Feed
DSouza
Calcite | Level 5

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

9 REPLIES 9
Reeza
Super User

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.

Darrell_sas
SAS Employee

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

Darrell_sas
SAS Employee

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

bpfields
Calcite | Level 5

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.

GraphGuy
Meteorite | Level 14

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)

GraphGuy
Meteorite | Level 14

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

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 9 replies
  • 3985 views
  • 10 likes
  • 6 in conversation