BookmarkSubscribeRSS Feed
P5C768
Obsidian | Level 7

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
10 REPLIES 10
ballardw
Super User

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.

Capt_VA_SAS
SAS Employee

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.

Darrell_sas
SAS Employee

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

ballardw
Super User

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

P5C768
Obsidian | Level 7

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.

ballardw
Super User

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.

P5C768
Obsidian | Level 7

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!

Capt_VA_SAS
SAS Employee

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.

P5C768
Obsidian | Level 7

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.

Darrell_sas
SAS Employee

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.

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
  • 2430 views
  • 0 likes
  • 4 in conversation