BookmarkSubscribeRSS Feed
mrcodes
Calcite | Level 5

I have a dataset with latitude and longitude coordinates  and I need to derive zip code for each of the observations across multiple years. I have explored proc geocode and proc ginside but have not found a solution.

 

It seems like there should be a simple solution to reverse geocode my x y coordinates to get those zip codes.

 

For example:

DATA mydata;
INPUT year county $ x y;
CARDS;
2019 Thurston 47.041853, -122.918215
2020 Adams 47.121696, -118.376568
2021 Whatcom 48.914895, -122.635580
2022 Pierce 47.237745, -122.445695
2022 King 47.505950, -122.270104
;
RUN;

 

Thanks!

5 REPLIES 5
ballardw
Super User

Ginside would be the proper tool but finding a data set by calendar year to have Zip code boundaries and looking up in the proper set is going to be a bit of work.

 

Since you don't show your approach using Ginside or the Zip code boundary data set it would require can't comment on what you are missing.

mrcodes
Calcite | Level 5

Thanks. I haven't really taken a stab at the code using GINSIDE, just sort of looking at approaches online.

 

It looks like a lot of people refer sashelp.zipcode. 

 

If you have any insights for where to begin, it would be greatly appreciated.

ballardw
Super User

The US Census bureau website does have Zip code tabulation area boundary data sets. However they do not provide exhaustive map coverage in areas with low population density areas like much of Nevada and parts of other western states. I am not going to spend the time searching for them as the Census bureau redesigns its website an the last links I found are 8 years ago so likely changed.

Since the purpose I had for geocoding required stuff in those low density areas I had to abandon that data source which at least has the advantage of being free.

 

The SASHELP.Zipcode data set has centroid coordinates of Zip code area but not boundaries. You could find a Zip close to a set of coordinates, which might be accurate for determining a city but is not likely to work well for finding the actual Zip code inside a high population density area as Zip codes can be as small as a single building if it generates enough mail. This data set is used by SAS for the functions like ZIPCITYDistance and the lookup functions like ZIPCity, Zipfips, Zipname, Zipnamel and Zipstate.

 

 

mrcodes
Calcite | Level 5

I see your points. It seems there could be some work arounds, but that it is unlikely to get 100% reliable zip codes from the x y coordinates I have.

 

Thank you for your input.

ballardw
Super User

@mrcodes wrote:

I see your points. It seems there could be some work arounds, but that it is unlikely to get 100% reliable zip codes from the x y coordinates I have.

 

Thank you for your input.


There are services that charge real $$$ do such. If you don't have money for such the Census Zip are the only map files I am aware of that are free that are close to comprehensive.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 5 replies
  • 736 views
  • 1 like
  • 2 in conversation