Data visualization with SAS programming

how to color zip code on a US state map?

Reply
Super Contributor
Posts: 314

how to color zip code on a US state map?

my data has zip code column, and we want to see which area of the state has more of the IDs.

One way is to color the zip code on the state map, with color related by zip code frequency

 

Is there a way to do this in SAS with gmap? Does any one know such an example?

 

thanks

Super User
Posts: 11,101

Re: how to color zip code on a US state map?

First question: Do you have a MAP dataset with Zipcode boundaries? Or are you going to use a center of mass for each Zipcode?

Note: on many STATE level maps Zip code areas can be so small not to be visible, especially if any of the Zip codes you use are of the single building (company) variety.

 

Do you want to show specific levels of counts such as 1 to 10, 11 to 50, 51 to 100 Ids with each Group having an separate color or a gradient based on count?

 

Also consider using cirles where the radius indicates number if you have lots of Zip codes close together.

Super Contributor
Posts: 314

Re: how to color zip code on a US state map?

You are right. Zip code area may be too small. We are thinking group then into 8 regions.

gradient color map may be better; but if it is too hard, color at different levels is also ok.

I tried to download the ZCTA files with the links in this post: https://communities.sas.com/t5/SAS-GRAPH-and-ODS-Graphics/One-County-with-Zips-Map/td-p/77822 but the inks did not work.
Super User
Posts: 11,101

Re: how to color zip code on a US state map?

Depending on the state the ZCTA has lots of holes in it and may not look very good. You may consider county as the SASHELP.ZIPCODE would help match the zip to counties for counting and then use one of the SAS supplied county map data sets.

Super Contributor
Posts: 314

Re: how to color zip code on a US state map?

Thank you, Ballardw.
I know zipname can return state name, zipcity can return city, is there a zip function can return counties?

Super User
Posts: 11,101

Re: how to color zip code on a US state map?

Use a Proc SQL join.Note that the Zip code dataset also has latitude and longitude for approximate center if that might be helpful.

 

(pseudo code as I am away from my SAS install)

proc sql;
   create table MyStateZips as
   select distinct zip, county
   from sashelp.zipcodes
where statecode = 'XX'; quit;

to get zipcodes for a single state of interest.

Then to look up the county name something like

Proc sql;
   create MyMergeData as
   select have.*, MyStateZips.county
   from have left join MyStateZips on
      have.zip = MyStateZips.zip;
quit;
   

If you are working in multiple states then you would have to add the state values to the select in the first bit and add to the join in the second.

 

 

I actually pulled a unique list of Zip code/county name values for my state of interest and built a number of formats and informats to do the common transformations as I have the opportunity to do something with Zip codes moderately often. I also made sure my county map dataset had numeric and text values for such things as the Fips code, county sequence number as well as county name so that I could often go to mapping with most likely types of county identifiers.

SAS Super FREQ
Posts: 3,615

Re: how to color zip code on a US state map?

A slightly different approach: Many statisticians who are interested in spatial data analysis use metropolitan statistical areas (MSAs) instead of zip codes.  MSAs are used by the US census bureau.

Super Contributor
Posts: 314

Re: how to color zip code on a US state map?

I realized drawing a map and color the zipcode or region on the map takes a lot of work.

so maybe I do not need such a fancy map but just some charts.

 

Thanks a lot for all replies.

Ask a Question
Discussion stats
  • 7 replies
  • 589 views
  • 0 likes
  • 3 in conversation