BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
KathyWiz
Calcite | Level 5

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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.

View solution in original post

10 REPLIES 10
Fugue
Quartz | Level 8

Have you taken a look at the SASHELP.ZIPCODE dataset?

Fugue
Quartz | Level 8

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).

ballardw
Super User

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.

Reeza
Super User

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.

KathyWiz
Calcite | Level 5

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.

art297
Opal | Level 21

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.

Doc_Duke
Rhodochrosite | Level 12

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

art297
Opal | Level 21

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?

Reeza
Super User

Its not my suggestion, its Smiley Happy

But I will test it with Canadian data...out of curiousity. I have ArcGIS that can be the source of "truth"

data_null__
Jade | Level 19

You seem to forget the OP has long and lat for each address.  No need to involve ZIP code that I can see.

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
  • 10 replies
  • 9260 views
  • 3 likes
  • 7 in conversation