Is there a way to take a set of latitude and longitude coordinates and reverse geocode them to get 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 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:
Here is an example using the google geocoding service. It can be adapted for reverse geocoding.
An interface for using Google Geocode API with PROC GROOVY in SAS
Another implementation of using Google geocoding API in SAS, this time using PROC FCMP
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:
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.
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)
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;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.