BookmarkSubscribeRSS Feed
sjoki
Calcite | Level 5

If I provide over 10,000 zipcodes or a population set of 60,000 zipcodes all across usa, the map

is tilted or shrinks to a non-readable image

would like to hear if there is some limit of zipcodes that can not be exceeded or solution

to be able to provide the actual zipcodes available without fear of losing readability?

using the following sample code, this works fine

/* Set the graphics environment */

goptions reset=all border;

/* Create a data set containing ZIP codes */

data myzip;

   input zip;

   datalines;

00602

35004

85003

71601

80002

06001

19701

20001

32007

83201

60001

46001

50001

66002

40003

70001

03901

20601

01001

27513

96701

99501

;

run;

/* Sort the data set by ZIP codes */

proc sort data=myzip;

   by zip;

run;

/* Create a data set containing the */

/* X and Y values for my ZIP codes  */

data longlat;

   merge work.myzip(in=mine) sashelp.zipcode(rename=(x=long y=lat));

   by zip;

  /* Keep if the ZIP code was in my data set */

   if mine;

  /* Convert longitude and latitude in degrees to radians */

  /* to match the values in the map data set */

   x=atan(1)/45*long;

   y=atan(1)/45*lat;

  /* Adjust the hemisphere */

   x=-x;

  /* Keep only the ZIP, X, Y, and STATE variables */

   keep zip x y state;

run;

/* Create an annotate data set to place a symbol */

/* at ZIP code locations. */

data anno;

  /* Use the X and Y values from the LONGLAT data set */

   set longlat;

  /* Set the data value coordinate system */

  /* Set the function to LABEL */

  /* Set the size of the symbol to .75 */

  /* Set a FLAG variable to signal annotate observations */

   retain xsys ysys '2' function 'label' size .75 flag 1 when 'a';

  /* Set the font to the Special font */

   style='special';

  /* The symbol is a star */

   text='M';

  /* Color for the symbol */

   color='depk';

  /* Output the observation to place the symbol */

   output;

run;

/* Since we want to move Alaska, Hawaii, and Puerto Rico under */

/* the continental U.S., we need to separate their coordinates */

/* so they can be projected separately. */

data states alaska hawaii pr;

   set maps.states;

   select;

      when (state=2) output alaska;

      when (state=15) output hawaii;

      when (state=72) output pr;

      otherwise output states;

   end;

run;

/* Separate the annotate data for the continental U.S., */

/* Alaska, Hawaii, and Puerto Rico to be projected with */

/* their state coordinates. */

data stateszip alzip hizip przip;

   set anno;

   select;

      when (state=2) output alzip;

      when (state=15) output hizip;

      when (state=72) output przip;

      otherwise output stateszip;

   end;

run;

/* Combine the map and annotate data sets */

/* for the contiguous states.  */

data states;

   set states stateszip;

run;

/* Project the data */

proc gproject data=states out=stproj;

   id state;

run;

/* Combine the Alaska map and annotate data */

data alaska;

   set alaska alzip;

run;

/* Project Alaska so it will appear full size under the U.S. */

proc gproject data=alaska out=akproj;

   id state;

run;

/* Combine the Hawaii map and annotate data */

data hawaii;

   set hawaii hizip;

run;

/* Project Hawaii */

proc gproject data=hawaii out=hiproj;

   id state;

run;

/* Combine the Puerto Rico map and annotate data */

data pr;

   set pr przip;

run;

/* Project Puerto Rico */

proc gproject data=pr out=prproj;

   id state;

run;

/* Adjust the coordinates for Alaska to move */

/* it under the continental U.S. */

data akproj(drop=x y);

   set akproj;

   if density < 2;

   newx=(x-.55)*.50;

   newy=(y-.35)*.50;

run;

/* Adjust the coordinates for Hawaii to move */

/* under the continental U.S. */

data hiproj(drop=x y);

   set hiproj;

   newx=x-.12;

   newy=y-.20;

run;

/* Adjust the coordinates for Puerto Rico */

data prproj(drop=x y);

   set prproj;

   newx=(x+.315);

   newy=(y-.24);

run;

/* Combine all of the projected data sets */

data all;

   set stproj akproj(rename=(newx=x newy=y))

              hiproj(rename=(newx=x newy=y))

              prproj(rename=(newx=x newy=y));

run;

/* Separate the projected data set into a map and an annotate data set */

data map dot;

   set all;

  /* If the FLAG variable has a value of 1, it is an annotate data */

  /* set observation; otherwise, it is a map data set observation. */

   if flag=1 then output dot;

   else output map;

run;

/* Define the pattern for the map */

pattern1 v=me c=grp r=50;

/* Define the title for the map. */

title1 'ZIP Code locations on a US Map';

title2 'moving Alaska, Hawaii and Puerto Rico';

filename odsout 'E:\Temp';

ods listing close;

*goptions reset=global gunit=pct cback=white

         colors=(black blue green red)

         ftext=swiss ftitle=swissb htitle=6 htext=4;

goptions device=gif transparency noborder;

ods html body='map.html'

          path=odsout;

/* Generate the map and place the symbols at ZIP code locations */

proc gmap data=map map=map;

   id state;

   choro state / anno=dot nolegend;

run;

quit;

ods html close;

ods listing;

1 REPLY 1
GraphGuy
Meteorite | Level 14

You should be able to plot all the zip codes onto the map, without causing any problems that distort/shrink the map.  Here's a bare-bones example that plots all the zip codes onto the US map:

set sashelp.zipcode;
function='point'; color='red';
xsys='2'; ysys='2'; when='a';
   x=atan(1)/45*x;
   y=atan(1)/45*y;
run;

data map; set maps.states;
x=x*-1;
run;

proc gmap data=map map=map anno=zips;
id state;
choro state / levels=1 nolegend;
run;

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
  • 1 reply
  • 557 views
  • 0 likes
  • 2 in conversation