BookmarkSubscribeRSS Feed
sanjay1
Obsidian | Level 7

Am trynig to draw a choropleth map for all states of us using zipcodes. 

Following is the error:  

 

PROBLEM IN OBSERVATION 2 -
DATA SYSTEM REQUESTED, BUT VALUE IS NOT ON GRAPH 'X'
NOTE: PROBLEM IN OBSERVATION 3 -
DATA SYSTEM REQUESTED, BUT VALUE IS NOT ON GRAPH 'X'
NOTE: PROBLEM IN OBSERVATION 4 -
DATA SYSTEM REQUESTED, BUT VALUE IS NOT ON GRAPH 'X'

 

below is the code....

proc sort data=allx out=myzip ;by Postal_Zip___Personal_Dta; run;

/* convert data type of Postal_Zip___Personal_Dta to numeric */
data myzip1;
set myzip;
zip1=put(input(Postal_Zip___Personal_Dta,5.),z5.);
run;

data myzip1;
set myzip1;
format zip z5.;
zip=zip1*1;
run;

proc sort data=myzip1 out=myzip2;by zip;run;

/* Create a data set containing the */
/* X and Y values for my ZIP codes. */

data longlat;
/* In case there are duplicate ZIP codes, rename
X and Y from the SASHELP.ZIPCODE data set. */
merge myzip2(in=mine)
sashelp.zipcode(rename=(x=long y=lat)keep=x y zip);
by zip;
/* Keep if the ZIP code was in my data set. */
if mine;
/* Convert longitude, 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;
run;

 

 

%let color1=cxF3F7FE;
%let color2=cx6497EB;


proc template;
define style styles.colorramp;
parent=styles.default;
style twocolorramp / startcolor=&color1 endcolor=&color2;
class body / backgroundcolor=white;
class table / backgroundcolor=white;
class header, footer / backgroundcolor=white;
class data / backgroundcolor=white;
class systemtitle / backgroundcolor=white;
end;
run;


/* Create an annotate data set  */

data stlabel_zip;
length function style color $ 10 position $ 1 text $5;
retain flag 1 function 'label' xsys ysys '2' hsys '3' when 'a' ;

set longlat;
color= 'black';
text=put(stcnt,comma5.);
position = '5';
size = 2.5;
style = 'colorramp';
output;
run;

data all;
/* Subset out the states that you do not want. */
/* The FIPS code of 2 is Alaska, 15 is Hawaii, */
/* and 72 is Puerto Rico. */
set maps.states(where=(state not in(2 15 72))) stlabel_zip;
run;
proc gproject data=all out=allproj;
id state;
run;
quit;


data map dot;
set allproj;
/* If the FLAG variable has a value of 1, it is an annotate */
/* observation; otherwise, it is a map data set observation. */
if flag=1 then output dot;
else output map;
run;

proc gmap data=map map=map;
id state;
choro zip / anno=dot nolegend;
run;
quit;

3 REPLIES 3
Darrell_sas
SAS Employee

I don't understand your Proc GMAP.  You have "choro zip" but I don't see where you assigned "zip" to MAP. 

I put a data step above your code with the ZIP Code for SAS:

data allx;

Postal_Zip___Personal_Dta='27513'; output;

run;

And I changed the "choro state" and it produces a small dot in NC where that ZIP code is.

 

If yours is working and drawing the dots, it could be that you have ZIP Codes that are on the coast or on an island and the map isn't fine grained enough to show the exact coast line.  These will produce that message if it is slightly in the water.

 

You may want to make your dots bigger.  This macro will do that:

/*-----------------------------------------------------------*/
/* Macro to create point data in an annotate data set
 * annodata = point annotate data set created. 
 * inputdata = Input data set containing points to be drawn.
 *      Note that this data must contain variables x and y
 *      with the location of the points.
 * color = Graph color.  eg: red
 * size = dot size (optional).  Default is .7;
 * tipvar = Variable name to be used for tool tip (optional).
 * Note:  search for ????? for items that can be modified.
 */   
%macro make_dots(annodata, inputdata, color, size, tipvar);
data &annodata;
  length function color $ 8 style $20 position $ 1 text $ 60 html $1024;
  retain xsys ysys '2' hsys '3' when 'a' size .7;
  set &inputdata;
  /*optional arguments*/
  %if (&size ^= ) %then %do;
    size=&size;
  %end;
  /* All annotate points are 360-degree pies.  */
  function='pie';
  rotate=360;
  style='psolid';
  color=&color;

  /* optional tool tips */
  %if (&tipvar ^= ) %then %do;
    html= 'title=' || quote("&tipvar" ||'=' || trim(left(&tipvar)) );
  %end;
  output;
run;
%mend;

sanjay1
Obsidian | Level 7

Hi,

Following is my data, and I want to draw a map for count of  stcnt at  zipcode level  for each statecode.

I have three variables Zip Stcnt Statecode.

data allx;
input zip statecode$ stcnt;
cards;
07302 NJ 18
80012 CO 2
00602 PR 24
00646 PR 26
00646 PR 45
01001 CT 26
01010 MA 45
01050 MA 56
01056 CT 68
02155 NH 69
02339 RI 14
02351 RI 09
03873 NH 56
04005 ME 76
04021 ME 68
05408 VT 09
0623 CA 21
07003 NY 24
07006 NY 19
07030 PA 66
28217 GA 9
28217 NC 56
29710 SC 08
29710 NC 89
30019 FL 78
30019 GA 68
30188 WI 45
32086 KS 56
32256 MA 44
32259 UT 42
32566 LA 8
33173 MD 44
3411 KY 42
35043 AL 56
35094 AL 45
37013 TN 22
;
RUN;

 

Please help.

 

Darrell_sas
SAS Employee

I had to change your program around to make it work.  In ALLX. you did not have Postal_Zip___Personal_Dta listed.

data allx;

input Postal_Zip___Personal_Dta $ statecode$ stcnt;

length zip 5;

zip=Postal_Zip___Personal_Dta;

cards;

 

And in the GMAP, i had to change 'CHORO ZIP' to "CHORO STATE".  ZIP must be in the "MAP" data set. 

CHORO does not work with the ANNOTATE data set.

 

Finally, your messages are coming out because you have Puerto Rico (PR) in your ZIP Codes and you do not have it in your map.

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1940 views
  • 0 likes
  • 2 in conversation