BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
AAWTomHanks
Calcite | Level 5

Hi,

I am trying to create a map of Cape May county (NJ) with the county broke apart into zips. Does anyone know how to do this?

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
MikeZdeb
Rhodochrosite | Level 12

hi ... first, get a shapefile of New Jersey ZCTAs (zip code tabulation areas) ... close to ZIPs

http://www.census.gov/cgi-bin/geo/shapefiles2012/main

that's for the most recent geography, but ZCTA files are available only for the entire country,. not separate states, and it's a HUGE file

you can get a file just for New Jersey based on 2002 ZCTAs at ...

2009 TIGER/Line® Shapefiles for: New Jersey

then try this (I used the New Jersey ZCTA shapefile from the 2nd link above) ...

* import shapefile of NJ ZCTAs (aka ZIPs);

proc mapimport datafile="z:\tl_2009_34_zcta5.shp" out=temp;

select zcta5ce;

run;

* make ZIP a numeric variable ... look up ZIP on SASHELP.ZIPCODE, keep Cape May county ZIPs;

data capemay;

set temp;

zip = input(zcta5ce,5.);

set sashelp.zipcode (keep=zip state county) key=zip / unique;

if _error_ then do;

   _error_ = 0;

   call missing (state, county);

end;

if state eq 34 and county eq 9;

drop zcta5ce;

run;

* list Cape May county zips;

proc sql;

select distinct zip from capemay;

quit;


* project the Cape May county ZIP map;

proc gproject data=capemay out=cmp degrees eastlong;

id zip;

run;

* draw an outline map;

goptions reset=all ftext='calibri' gunit=pct;

title h=4 'CAPE MAY COUNTY, NJ ZIPS (AS OF 2002)';

proc gmap map=cmp data=cmp;

id zip;

choro segment / levels=1 statistic=first nolegend;

run;

quit;

the above produced the attached map

(I also attached the SHAPEFILE in the attached zip file)


capemaynj.png

View solution in original post

8 REPLIES 8
MikeZdeb
Rhodochrosite | Level 12

hi ... first, get a shapefile of New Jersey ZCTAs (zip code tabulation areas) ... close to ZIPs

http://www.census.gov/cgi-bin/geo/shapefiles2012/main

that's for the most recent geography, but ZCTA files are available only for the entire country,. not separate states, and it's a HUGE file

you can get a file just for New Jersey based on 2002 ZCTAs at ...

2009 TIGER/Line® Shapefiles for: New Jersey

then try this (I used the New Jersey ZCTA shapefile from the 2nd link above) ...

* import shapefile of NJ ZCTAs (aka ZIPs);

proc mapimport datafile="z:\tl_2009_34_zcta5.shp" out=temp;

select zcta5ce;

run;

* make ZIP a numeric variable ... look up ZIP on SASHELP.ZIPCODE, keep Cape May county ZIPs;

data capemay;

set temp;

zip = input(zcta5ce,5.);

set sashelp.zipcode (keep=zip state county) key=zip / unique;

if _error_ then do;

   _error_ = 0;

   call missing (state, county);

end;

if state eq 34 and county eq 9;

drop zcta5ce;

run;

* list Cape May county zips;

proc sql;

select distinct zip from capemay;

quit;


* project the Cape May county ZIP map;

proc gproject data=capemay out=cmp degrees eastlong;

id zip;

run;

* draw an outline map;

goptions reset=all ftext='calibri' gunit=pct;

title h=4 'CAPE MAY COUNTY, NJ ZIPS (AS OF 2002)';

proc gmap map=cmp data=cmp;

id zip;

choro segment / levels=1 statistic=first nolegend;

run;

quit;

the above produced the attached map

(I also attached the SHAPEFILE in the attached zip file)


capemaynj.png
AAWTomHanks
Calcite | Level 5

Thanks appreciate the help.

AAWTomHanks
Calcite | Level 5

Hi,

I was wondering if you knew how to put markers on this type of map. I am using zipcode markers but since a zipcode is outlined is there anyway to put the marker in the middle of the zipcode?

Thanks.

ballardw
Super User

There is a SAS supplied macro %CENTROID that should be able to take the regions defined for your Zip codes and find an approximate center. Then use those locations to plot your marker with an Annotate data set.

Be prepared to fiddle with the locations, meaning manually edit the X and Y coordinates, to get some markers to look well placed as the calculated coordinates may result in placement near boundaries depending on the actual shape of the area.


MikeZdeb
Rhodochrosite | Level 12

Hi ... zip centroids are part of the data set SASHELP.ZIPCODE, so using the same NJ shapefile as last time (produced the attached) ...

* import shapefile of NJ ZCTAs (aka ZIPs);

proc mapimport datafile="z:\tl_2009_34_zcta5.shp" out=temp;

select zcta5ce;

run;

* make ZIP a numeric variable ... look up ZIP on SASHELP.ZIPCODE, keep Cape May county ZIPs;

data capemay;

set temp;

zip = input(zcta5ce,5.);

set sashelp.zipcode (keep=zip state county) key=zip / unique;

if _error_ then do;

   _error_ = 0;

   call missing (state, county);

end;

if state eq 34 and county eq 9;

drop zcta5ce;

run;

* make a data set of Cape May county zips;

proc sql;

create table zcapemay as

select distinct zip from capemay;

quit;

* find centroids;

data zcapemay;

set zcapemay;

set sashelp.zipcode (keep=zip x y) key=zip / unique;

if _error_ then do;

   _error_ = 0;

   call missing (x , y);

end;

run;

* combine map data set with zip centroids;

data all_capemay;

set capemay zcapemay;

run;

* project the combined file;

proc gproject data=all_capemay out=cmp degrees eastlong;

id zip;

run;

* separate the projected map from the project zip centroids;

data cmp zips;

set cmp;

if segment then output cmp;

else output zips;

run;

* make an annotate data set to put a label on each zip;

data zip_labels;

retain xsys ysys '2' hsys '3' function 'label' style 'calibri' size 2 color 'blue' cbox 'white' when 'a';

set zips;

text = put(zip,z5.);

run;


* make an annotate data set to put a marker on each zip;

data zip_markers;

retain xsys ysys '2' hsys '3' function 'label' style 'wingdings' text 'ab'x size 5 color 'yellow' when 'a';

set zips;

run;

* draw an outline map with zip labels or markers;

goptions reset=all ftext='calibri' gunit=pct;

title h=4 'CAPE MAY COUNTY, NJ ZIPS (AS OF 2002)';

* use appropriate data set to annotate;

proc gmap map=cmp data=cmp annotate=zip_markers;

id zip;

choro segment / levels=1 statistic=first nolegend;

run;

quit;



cape_may_zip_markers.pngcape_may_zip_labels.png
AAWTomHanks
Calcite | Level 5

Thanks appreciate the help again.

AAWTomHanks
Calcite | Level 5

Hey MikeZdeb,

So the map I built using the code given looks great I made it for two counties Cape May and Atlantic together. I have a question though.Is there any way to make the outline of the county a darker line or more distinguishable? That way it is easier to tell where Cape May or Atlantic County starts.

As always I appreciate the help.

Thanks.

GraphGuy
Meteorite | Level 14

There's no built-in gmap feature to do that (wish there was!)

One work-around is to create an annotate data set that draws a thick/dark county outline, and then overlay that onto the zipcode map.

Here's an example that shows how to annotate a state outline onto a county map (this example/technique is described in detail in the book SAS/Graph: Beyond the Basics, in Example 12):

http://robslink.com/SAS/book/example12.htm

http://robslink.com/SAS/book/example12_info.htm

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
  • 8 replies
  • 2024 views
  • 6 likes
  • 4 in conversation