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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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