06-25-2015 11:07 AM
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:
Similar to the example by Dr. Allison found here, except for the whole U.S. rather than just North Carolina:
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;
rename geoid10 = ZIP;
drop aland10 awater10 classfp10 funcstat10 intptlat10 intptlon10 mtfcc10 zcta5ce10;
Statecode = zipstate(geoid10);
State = zipfips(geoid10);
proc gproject data=Map_Zip out=Map_Zip eastlong degrees project=robinson;
ods listing close;
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");
choro State / nolegend;
ODS HTML5 CLOSE;
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!
06-25-2015 11:31 AM
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.
06-25-2015 12:44 PM
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.
06-25-2015 02:44 PM
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).
06-25-2015 04:06 PM
And if you pick a lower population density state such as Idaho, Nevada, Montana you see lots of area not covered by any ZCTA.
06-25-2015 05:35 PM
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.
06-25-2015 06:41 PM
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.
06-25-2015 11:16 PM
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!
06-26-2015 09:15 AM
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.
06-26-2015 11:44 AM
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.
06-26-2015 02:13 PM
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.