I have files which contain data for addresses that have been geocoded. They contain latitude and longitude. Is there a way (a function or procedure) within SAS that will return the U.S. county from these coordinates?
There's a proc for that!
SAS/GRAPH(R) 9.2: Reference, Second Edition
Ballardw suggest is probably the easiest and the example in the documentation is for example that problem.
If the projections don't match you can also find the proper version for US county data online in many places and bring that into SAS.
Have you taken a look at the SASHELP.ZIPCODE dataset?
Ballard's suggestion may be preferable, but to elaborate further on my comment . . . .one could use GEODIST function to determine the closest location in the ZIPCODE dataset. This would be somewhat hit-and-miss, since the closest location may, in fact, be in a different county. Ideally, Ballard's approach makes better sense since your lat and long can only fall into unique counties (unless it happens to be exactly on a county boundary).
If you can get the lat and long projected (Proc Gproject) to match the USCounty map dataset provided by SAS then Proc Ginside should work.
There's a proc for that!
SAS/GRAPH(R) 9.2: Reference, Second Edition
Ballardw suggest is probably the easiest and the example in the documentation is for example that problem.
If the projections don't match you can also find the proper version for US county data online in many places and bring that into SAS.
Thanks for the link and suggestions. I haven't worked with geographic data before, so it is very helpful to be pointed in the right direction.
This questions was actually something I was asked by another programmer, so I'll forward the comments to her so she can try this out.
Just FWIW, if you enter a coordinate pair as a search string at www.mapquest.com, part of the output will contain the zipcode, city and state and, given that info, you can get the county name from sashelp.zipcode.
The following paper provides example code for automating such a lookup process:
http://support.sas.com/resources/papers/proceedings12/091-2012.pdf
To use it, you would have to get an API key from Mapquest, but that is free and easily done from their web site.
One caution with Arthur's approach. At least in NC, ZIP codes and City boundaries cross county lines.
Reeza's approach will have more precision.
Doc Muhlbaier
Duke
Doc: Before mentioned it, I wasn't even aware of proc ginside and it is definitely the easiest to implement. However, since both methods start with coordinates thus should be attempting to match with polygons, I wouldn't jump to the conclusion that one would necessarily be more accurate than the other. Can you provide a couple of examples that we could compare?
You seem to forget the OP has long and lat for each address. No need to involve ZIP code that I can see.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.