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

I am creating a map of a single metro area with the data mapped at the zip code level.  I downloaded the ZTCA tiger file from the census website.  I want to annotate the map with the county lines.  When I create the annotate dataset for the county lines the counties do not line up correctly to the zip code dataset.  I was able to partially correct the annotate data by assigning the parallel1 and parallel2 values in the proc gproject for the county lines.  But the lines are still shifted off to the right slightly.  Is there a way to force the longitude values to line up like the latitude values?

Here is the code to project the zip code map:

data longlat;

  set smk.&filename(in=mine);

  if mine;

  x=atan(1)/45*x;

  y=atan(1)/45*y;

  x=-x;

run;

proc gproject data=longlat out=smk.map ;

  id zip;

run;

Here is the code for creating the annotate dataset that labels the zipcodes, maps the county lines, and labels the counties.

options orientation=&orient;

goptions

rotate=&orient

;

%annomac;

%centroid(smk.map,zip,zip);

data smk.anno1;

  length color $ 8 function $ 10 text $ 20;

  set zip;

  position='5';

  xsys='2';

  ysys='2';

  when='a';

  hsys='3';

  text=trim(put(zip,5.));

  function='label';

  style='Albany AMT/bold';

  color='blue';

  if zip in (43202 43211 43201 43203 43205 43215 43210 43209 43206 43205 43222) then do

  size=.5;

  color='black';

  end;

  else size=.75;

  keep position xsys ysys when hsys text function style color size x y;

run;

data county;

  set smk.county01(in=mine);

  if mine;

  x=atan(1)/45*x;

  y=atan(1)/45*y;

  x=-x;

run;

proc gproject data=county out=smk.counties01 parallel1=39.658156 parallel2=40.316822;

  id countyfp;

run;

data smk.anno2;

  length function $ 10;

  set smk.counties01;

  by countyfp notsorted;

  position='5';

  xsys='2';

  ysys='2';

  when='a';

  hsys='3';

  if first.countyfp=1 then function='poly';

  else function='polycont';

  color='black';

  size=2;

  keep position xsys ysys when hsys text function style color size x y countyfp;

/* put _N_= county= first.county= function=;*/

run;

proc sort data=smk.counties01;

  by countyfp;

run;

%centroid(smk.counties01,smk.counties02,name);

data smk.anno3;

  length function $ 10 text $ 20;

  set smk.counties02;

  position='5';

  xsys='2';

  ysys='2';

  when='a';

  hsys='3';

  function="label";

  text=name;

  style='Albany AMT/bold';

  color='gray';

  size=2;

  keep position xsys ysys when hsys text function style color size x y name;

/* put _N_= county= first.county= function=;*/

run;

data smk.annotate;

set smk.anno1 smk.anno2 smk.anno3;

run;

And finally the code to create the map.

proc gmap data=smk.map map=smk.map all;

id zip; /* matches values between response and map dataset */

choro &Var / anno=smk.annotate levels=10

range legend=legend1

/* response variable */

/* pattern/color levels */

/*nolegend */

coutline=black

woutline=1;

run;quit;


map_sample.JPG
1 ACCEPTED SOLUTION

Accepted Solutions
GraphGuy
Meteorite | Level 14

If you try combining the *unprojected* county and zipcode maps, and plotting them with gplot (either drawing them with lines using interpol=join, or even just plotting as scatter plot points), do the two maps seem to line up? Also, you might want to specify the projection parameters on both the county and zipcode maps, to make sure they're projected exactly the same (if no parameters are specified, then gproject picks default values, based on the min/max extents of the map points it is projecting).

As an alternative to *guarantee* that the 2 maps are projected using the exact same parameters, you could combine the two maps, and project them together, and then separate them again. Here is an example where I use proc gmap to draw the zipcode map, and annotate to overlay the county outline:

http://robslink.com/SAS/democd69/wake_county_demographics.htm

http://robslink.com/SAS/democd69/wake_county_demographics_info.htm

wake_county_demographics.png

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

I was not aware that zip code boundaries (created and maintained by the US Post Office) had to match county boundaries (created by local and state governments). In fact, a quick Google search comes up with examples where a single zip code spans parts of multiple counties, and the fact that about 20% of zip codes span parts of multiple counties.

--
Paige Miller
StephenKelty
Calcite | Level 5

I am aware that not all zip codes will fall within the counties.  The issue is that some of the boundaries should match up.  And on the map I'm producing those boundaries are shifted slightly off from each other.  The image I attached above shows an example of that.  The dark black line is the county boundary.  On the right edge of the center county (Franklin) there is are 2 "straight" lines that meet to form the corner of the county.  The zip codes match this pattern, but are off to the left of the county line.  On the left side of the same county the boundary is not straight and probably follows a river.  There are multiple zip codes that have the exact same boundary pattern, but again shifted slightly to the left of the county line. 

There are several places on the map where it is apparent that the county and zip code boundaries should match up but don't. 

GraphGuy
Meteorite | Level 14

If you try combining the *unprojected* county and zipcode maps, and plotting them with gplot (either drawing them with lines using interpol=join, or even just plotting as scatter plot points), do the two maps seem to line up? Also, you might want to specify the projection parameters on both the county and zipcode maps, to make sure they're projected exactly the same (if no parameters are specified, then gproject picks default values, based on the min/max extents of the map points it is projecting).

As an alternative to *guarantee* that the 2 maps are projected using the exact same parameters, you could combine the two maps, and project them together, and then separate them again. Here is an example where I use proc gmap to draw the zipcode map, and annotate to overlay the county outline:

http://robslink.com/SAS/democd69/wake_county_demographics.htm

http://robslink.com/SAS/democd69/wake_county_demographics_info.htm

wake_county_demographics.png

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
  • 3 replies
  • 2102 views
  • 0 likes
  • 3 in conversation