/* 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 6001 19701 20001 32007 83201 60001 46001 50001 66002 40003 70001 3901 20601 1001 27513 96701 99501 11801 ; 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'; /* 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;