Data visualization with SAS programming

Import US Zip Code Shapefiles for TigerLines

Reply
Frequent Contributor
Posts: 84

Import US Zip Code Shapefiles for TigerLines

Hi there, I am trying to import all US zip codes as a shapefile into SAS via the Census Buearu Tiger Lines site found here:

2014 TIGER/Line® Shapefiles:

Similar to the example by Dr. Allison found here, except for the whole U.S. rather than just North Carolina:

http://robslink.com/SAS/democd17/zcta_info.htm

However, after using the code below I get the map output that is attached, it appears to partially work but comes out very small and hard to see:

proc mapimport out=Map_Zip datafile="/sas/Shape Files/Zip Code Shapefiles/tl_2014_us_zcta510.shp"; run;

data Map_Zip;

  set Map_Zip;

  rename geoid10 = ZIP;

  drop aland10 awater10 classfp10 funcstat10 intptlat10 intptlon10 mtfcc10 zcta5ce10;

  Statecode = zipstate(geoid10);

  State = zipfips(geoid10);

run;

proc gproject data=Map_Zip out=Map_Zip eastlong degrees project=robinson;

  id ZIP;

run;

ods listing close;

goptions reset=all;

ods html5 path = '/sas/' (url=none) file='ZIP.html';

goptions hsize=15in vsize=10in;

goptions xpixels=250 ypixels=250;

proc gmap data=Map_Zip map=Map_Zip all;

  where Statecode not in ("AK", "HI", "PR");

  id ZIP;

  choro State / nolegend;

  run;

quit;

ODS HTML5 CLOSE;

ODS LISTING;

I have also tried using the TIGER2GIS macro available on SAS Maps online, but I'm not sure if that's needed and I can't seem to get the macro to accept the required variables, even when using the default values included.

Any help is greatly appreciated.  Thanks!


US Zip Codes.PNG
Super User
Posts: 11,134

Re: Import US Zip Code Shapefiles for TigerLines

The TIGER files are more concerned with addresses. So areas where there are no "addresses" or very few are not considered. If you look at a selected state such as Nevada, Idaho, Arizona or Utah you will see large areas not included. Find a map with towns and note that there aren't any in those areas.

Also since Zip codes are involved with mail delivery an area isn't assigned to a Zip until there is mail to be delivered.

SAS Employee
Posts: 4

Re: Import US Zip Code Shapefiles for TigerLines

I agree with ballardw.  Try using pre-defined ZIP shape files from https://www.census.gov/geo/maps-data/data/cbf/cbf_zcta.html

Also, reduce your density levels to view it a little cleaner.

SAS Employee
Posts: 170

Re: Import US Zip Code Shapefiles for TigerLines

ZIP Codes and ZCTAs are not the same.  But a ZCTA is close.  A ZCTA is more concerned with the Census than with mailing addresses.  https://www.census.gov/geo/reference/zctas.html

There are more than 29,000 ZIP Codes in the US.  This makes for a very cluttered map.  Even when looking at one state, it is hard to see all the ZCTAs (In NC, for example).

Super User
Posts: 11,134

Re: Import US Zip Code Shapefiles for TigerLines

And if you pick a lower population density state such as Idaho, Nevada, Montana you see lots of area not covered by any ZCTA.

Frequent Contributor
Posts: 84

Re: Import US Zip Code Shapefiles for TigerLines

I am not actually interested in the zip codes themselves, however I'm working a project where zip codes are the only available geographic data source (i.e. the custom regions I am trying to create do not line up with states or counties).

As an example of what I was hoping to do, was to read in the zip codes then use GREMOVE to dissolve the zip codes into the areas I am actually interested in.  Using the NC example, this would be similar to taking NC zip codes and using GREDUCE to dissolve them into a NC state map (but as I mentioned, my custom regions don't line up with states or counties).

I have been able to accomplish this in other GIS software, but I would like to get it all into SAS to automate the process and allow for regular updating.

Super User
Posts: 11,134

Re: Import US Zip Code Shapefiles for TigerLines

Pretty much exactly the same thing I was doing when I found out that there were egregious wholes in my state, Idaho, when using ZCTA areas.

If you have access to that other software and it has Zip code boundaries you like then you may be able to create an appropriate shape file and import that into SAS.

However with a Zip code available then there are latitude and longitude for the centroid of Zip codes in the SASHELP.Zipcode dataset that could be used for placing markers on maps after suitable projection. Even working with just a marker if your final map is going to be much larger than small areas, Rhode Island perhaps, markers will overlap and be indistinct to some extent.

Good luck.

Frequent Contributor
Posts: 84

Re: Import US Zip Code Shapefiles for TigerLines

Sorry, I'm not following.  Are you saying it is possible to accomplish what I am attempting using sashelp.zipcode?  I avoided that option because it uses the centroid method and didn't think the dissolve would work properly, so i turned to shapefiles.  The software I am currently using to create the shapefiles does work, but the process is very labor intensive and the area change regularly, so I'm looking for a programmatc way to accomplish this task.

I'm familiar with the "holes" that zip codes produce, especially in CA, ID and ME, but I was hoping I would be able to at least reproduce what Dr. Allison accomplished in my original post.  Are you saying this is not possible?

Thanks again for all of your help!

SAS Employee
Posts: 4

Re: Import US Zip Code Shapefiles for TigerLines

SASHELP.Zipcodes will give you the centroids but can't be used for shapes.  PROC MAPIMPORT will build your SAS shape file from your *.shp file.  PROC GREDUCE will analyze your file and introduce density into the table so that you can reduce it if you want.  Warning, this will take some time with a file as large as the USZIPS.  I had to break it up in parts in order do it on my machine.

Frequent Contributor
Posts: 84

Re: Import US Zip Code Shapefiles for TigerLines

My apologies, I see now that I typed GREDUCE when I meant GREMOVE.  I agree shared.zipcodes won't work for what I am trying to accomplish, I was just trying to understand 's suggestion.

I still have the issue though of understanding why the map imports with such small graphics (as attached in my original post).  I understand I may have issues with "holes" in the map, but I'd still like to understand why importing the census bureau file results in the small map output.

SAS Employee
Posts: 170

Re: Import US Zip Code Shapefiles for TigerLines

What do you mean smaller?

The fact that the map has Puerto Rico on it will make the 48 US states slightly smaller.

And then the picture is small.  Make it bigger with GOPTIONS XPIXELS=800 YPIXELS=800;  Or whatever size you want.

Ask a Question
Discussion stats
  • 10 replies
  • 1026 views
  • 0 likes
  • 4 in conversation