BookmarkSubscribeRSS Feed
dding
Calcite | Level 5

Can you please help me to check the following code and revised to get what I want?

I want the color of the displayed counties' AREA to be changed to yellow. And let the rest counties to be black and white.  The counties to be yellow including: Chelan,Clallam,Ferry,Island,Jefferson,Kitsap,Lincoln,Okanogan,Pend Orielle, pierce,skagit, snohomish, spokane, stevens, thurston, whatcom, where the last part of the data set is greater than 7.9.

 

Thank you very much!!!

 

 

 

 

data sample(rename=(county=county_name));

input County $19. @21 Data $8.;

/* determine the name of the county to merge with MAPS.CNTYNAME to

obtain the county FIPS code */

countynm=upcase(transtrn(county,'County',''));

datalines;

Adams County 1/2/7.3

Asotin County 1/2/2.7

Benton County 1/2/9.2

Chelan County 1/2/9.7

Clallam County 1/2/19.8

Clark County 1/2/5.8

Columbia County 1/2/7.4

Cowlitz County 1/2/5.5

Douglas County 1/2/9.5

Ferry County 1/2/12.4

Franklin County 1/2/7.3

Garfield County 1/2/3.3

Grant County 1/2/6.5

Grays Harbor County 1/2/6.5

Island County 1/2/12.2

Jefferson County 1/2/10

King County 1/2/8.5

Kitsap County 1/2/10.4

Kittitas County 1/2/8.1

Klickitat County 1/2/3.4

Lewis County 1/2/6.7

Lincoln County 1/2/10.4

Mason County 1/2/8.5

Okanogan County 1/2/11.5

Pacific County 1/2/3.4

Pend Oreille County 1/2/11

Pierce County 1/2/9.8

San Juan County 1/2/9.6

Skagit County 1/2/16.9

Skamania County 1/2/7.1

Snohomish County 1/2/12.1

Spokane County 1/2/9.9

Stevens County 1/2/12.4

Thurston County 1/2/11.6

Wahkiakum County 1/2/5.5

Walla Walla County 1/2/5.4

Whatcom County 1/2/25.9

Whitman County 1/2/5.7

Yakima County 1/2/4.5

;

run;

proc sort; by countynm;

data sample2(drop=countynm);

merge sample maps.cntyname(where=(state=53) keep=state countynm county);

by countynm;

run;

/* project a county map of Washington */

proc gproject data=maps.counties out=wa;

where state=53 ;

id state county;

run;

/* make the annotate macros available */

%annomac;

/* determine the visual center of the county */

%centroid(wa,center,state county);

 

/* create an annotate data set to place the label */

Proc format;

value myrange

0 - <9.7 = '<9.7'

9.7 -high = '9.7+'

;

run;

data anno;

merge sample2 center;

by state county;

retain xsys ysys '2' when 'a' function 'label' color 'black' size 1;

length text $20;

Numericdata = input(scan(data,3,'/'),best5.);

if scan(data,3,'/')>9.7 then color='yellow';

County = strip(tranwrd(county,' County',''));

 

text=data;

position='5';

output;

text=county_name;

position='8';

output;

run;

 

/* You can define patterns to use to color the map areas using the

PATTERN statement */

/* create the map */

proc gmap data=sample2 map=wa;

id state county;

choro data / nolegend anno=anno;

run;

quit;

12 REPLIES 12
art297
Opal | Level 21

I don't have access to the SAS map library, thus can only mention that your initial data step needs some fixing:

 

data sample;
  input @;
  _infile_=transtrn(_infile_,'County',' ');
  informat countynm $19.;
  informat data $8.;
  input countynm & data $8.;
  /* determine the name of the county to merge with MAPS.CNTYNAME to
  obtain the county FIPS code */
  datalines;
Adams County 1/2/7.3
Asotin County 1/2/2.7
Benton County 1/2/9.2
Chelan County 1/2/9.7
Clallam County 1/2/19.8
Clark County 1/2/5.8
Columbia County 1/2/7.4
Cowlitz County 1/2/5.5
Douglas County 1/2/9.5
Ferry County 1/2/12.4
Franklin County 1/2/7.3
Garfield County 1/2/3.3
Grant County 1/2/6.5
Grays Harbor County 1/2/6.5
Island County 1/2/12.2
Jefferson County 1/2/10
King County 1/2/8.5
Kitsap County 1/2/10.4
Kittitas County 1/2/8.1
Klickitat County 1/2/3.4
Lewis County 1/2/6.7
Lincoln County 1/2/10.4
Mason County 1/2/8.5
Okanogan County 1/2/11.5
Pacific County 1/2/3.4
Pend Oreille County 1/2/11
Pierce County 1/2/9.8
San Juan County 1/2/9.6
Skagit County 1/2/16.9
Skamania County 1/2/7.1
Snohomish County 1/2/12.1
Spokane County 1/2/9.9
Stevens County 1/2/12.4
Thurston County 1/2/11.6
Wahkiakum County 1/2/5.5
Walla Walla County 1/2/5.4
Whatcom County 1/2/25.9
Whitman County 1/2/5.7
Yakima County 1/2/4.5
;
run;


proc sort;

   by countynm;

run;

 

dding
Calcite | Level 5

Thank you art297!

 

Your revised code makes sense, I like it.

 

Can you please find someone to check my code and give me a satisfied answer for my question? Please do not only give me one piece or two piece sentences everytime. It's hard for me to figure out. I'm still new to SAS.

 

Please provide me the full code!!! Thank you very much!

Reeza
Super User

@dding wrote:

 

 

Can you please find someone to check my code and give me a satisfied answer for my question? Please do not only give me one piece or two piece sentences everytime. It's hard for me to figure out. I'm still new to SAS.

 

Please provide me the full code!!! Thank you very much!


That's not how this works. If you want dedicated support please hire a consultant or consider opening up a ticket with SAS tech support. But we're not you're paid minions to do your work or assignment. Or whatever. 

ballardw
Super User

@dding wrote:

Can you please help me to check the following code and revised to get what I want?

I want the color of the displayed counties' AREA to be changed to yellow. And let the rest counties to be black and white.  The counties to be yellow including: Chelan,Clallam,Ferry,Island,Jefferson,Kitsap,Lincoln,Okanogan,Pend Orielle, pierce,skagit, snohomish, spokane, stevens, thurston, whatcom, where the last part of the data set is greater than 7.9.

 

/* create an annotate data set to place the label */

Proc format;

value myrange

0 - <9.7 = '<9.7'

9.7 -high = '9.7+'

;

run;


 

 

GMAP is set up to color the map areas based on the value of a data variable. You request coloring based on range of 7.9 but your data format MYRANGE is looking at 9.7. Is the 7.9 a typo or the format incorrect?

Assuming a typo in the request for 7.9 actually to be 9.7 then:

Your data set sample NEEDS to have a NUMERIC variable in addition to that "1/2/7.3". So add

NumericValue = input(scan(data,3,'/'),best5.);

to the code in your dataset Sample.

Then:

Pattern1 color=white;

Pattern2 color=yellow;

 

and the in gmap the Choro statement should be a numeric variable and assign the format Myrange to it:

Format NumericVariable Myrange. ;

 

 

 

AGAIN. Practically the exact same question as https://communities.sas.com/t5/SAS-GRAPH-and-ODS-Graphics/How-to-change-color-on-the-map-and-more/m-...

 

dding
Calcite | Level 5

Can anybody help me to check my code and give me a satisfied answer for my question? Please do not only give me one piece or two piece sentences everytime. It's hard for me to figure out what you mean.

 

Please provide me the full code!!! Thank you very much!

ballardw
Super User

First post your code in a CODE box. Use the {i} Icon in the forum.

 

I hate reformatting poorly structured code to add two lines.

dding
Calcite | Level 5

I'm sorry I didn't do this earily. I really depend you on this. Thank you very much!

 

 

 

{data sample;   input @;   _infile_=transtrn(_infile_,'County',' ');   informat countynm $19.;   informat data $8.;   input countynm & data $8.;   /* determine the name of the county to merge with MAPS.CNTYNAME to   obtain the county FIPS code */   datalines; Adams County 1/2/7.3 Asotin County 1/2/2.7 Benton County 1/2/9.2 Chelan County 1/2/9.7 Clallam County 1/2/19.8 Clark County 1/2/5.8 Columbia County 1/2/7.4 Cowlitz County 1/2/5.5 Douglas County 1/2/9.5 Ferry County 1/2/12.4 Franklin County 1/2/7.3 Garfield County 1/2/3.3 Grant County 1/2/6.5 Grays Harbor County 1/2/6.5 Island County 1/2/12.2 Jefferson County 1/2/10 King County 1/2/8.5 Kitsap County 1/2/10.4 Kittitas County 1/2/8.1 Klickitat County 1/2/3.4 Lewis County 1/2/6.7 Lincoln County 1/2/10.4 Mason County 1/2/8.5 Okanogan County 1/2/11.5 Pacific County 1/2/3.4 Pend Oreille County 1/2/11 Pierce County 1/2/9.8 San Juan County 1/2/9.6 Skagit County 1/2/16.9 Skamania County 1/2/7.1 Snohomish County 1/2/12.1 Spokane County 1/2/9.9 Stevens County 1/2/12.4 Thurston County 1/2/11.6 Wahkiakum County 1/2/5.5 Walla Walla County 1/2/5.4 Whatcom County 1/2/25.9 Whitman County 1/2/5.7 Yakima County 1/2/4.5 ; run;

proc sort;

   by countynm;

run;

proc sort; by countynm;

data sample2(drop=countynm);

  merge sample maps.cntyname(where=(state=53) keep=state countynm county);

    by countynm;

run;

/* project a county map of Washington */

proc gproject data=maps.counties out=wa;

  where state=53 ;

  id state county;

run;

/* make the annotate macros available */

%annomac;

/* determine the visual center of the county */

%centroid(wa,center,state county);

 

/* create an annotate data set to place the label */

data anno;

   merge sample2 center;

    by state county;

  retain xsys ysys '2' when 'a' function 'label' color 'black' size 1;

  length text $20;

  text=data;

  position='5';

  output;

  text=county_name;

  position='8';

  output;

run;

 

/* You can define patterns to use to color the map areas using the

   PATTERN statement */

/* create the map */

proc gmap data=sample2 map=wa;

  id state county;

  choro data / nolegend anno=anno;

run;

quit;

}

ballardw
Super User

Go to the menu of the box you are responding in. LOOK at the top. There is an icon that looks like {i}. Click on that icon. A box will open.

Paste the code into that box. Close the box by clicking on OK.

 

Note: The existing code you pasted for your data set SAMPLE is incorrect and does not have the full values of your "data" variable.

Make sure your data is correct.

dding
Calcite | Level 5
data sample;
  input @;
  _infile_=transtrn(_infile_,'County',' ');
  informat countynm $19.;
  informat data $8.;
  input countynm & data $8.;
  /* determine the name of the county to merge with MAPS.CNTYNAME to
  obtain the county FIPS code */
  datalines;
Adams County 1/2/7.3
Asotin County 1/2/2.7
Benton County 1/2/9.2
Chelan County 1/2/9.7
Clallam County 1/2/19.8
Clark County 1/2/5.8
Columbia County 1/2/7.4
Cowlitz County 1/2/5.5
Douglas County 1/2/9.5
Ferry County 1/2/12.4
Franklin County 1/2/7.3
Garfield County 1/2/3.3
Grant County 1/2/6.5
Grays Harbor County 1/2/6.5
Island County 1/2/12.2
Jefferson County 1/2/10
King County 1/2/8.5
Kitsap County 1/2/10.4
Kittitas County 1/2/8.1
Klickitat County 1/2/3.4
Lewis County 1/2/6.7
Lincoln County 1/2/10.4
Mason County 1/2/8.5
Okanogan County 1/2/11.5
Pacific County 1/2/3.4
Pend Oreille County 1/2/11
Pierce County 1/2/9.8
San Juan County 1/2/9.6
Skagit County 1/2/16.9
Skamania County 1/2/7.1
Snohomish County 1/2/12.1
Spokane County 1/2/9.9
Stevens County 1/2/12.4
Thurston County 1/2/11.6
Wahkiakum County 1/2/5.5
Walla Walla County 1/2/5.4
Whatcom County 1/2/25.9
Whitman County 1/2/5.7
Yakima County 1/2/4.5
;
run;

proc sort;
   by countynm;
run;

proc sort; by countynm;
data sample2(drop=countynm);
  merge sample maps.cntyname(where=(state=53) keep=state countynm county);
    by countynm;
run;
/* project a county map of Washington */
proc gproject data=maps.counties out=wa;
  where state=53 ;
  id state county;
run;
/* make the annotate macros available */
%annomac;
/* determine the visual center of the county */
%centroid(wa,center,state county);
 
/* create an annotate data set to place the label */
data anno;
   merge sample2 center;
    by state county;
  retain xsys ysys '2' when 'a' function 'label' color 'black' size 1;
  length text $20;
  text=data;
  position='5';
  output;
  text=county_name;
  position='8';
  output;
run;
 
/* You can define patterns to use to color the map areas using the
   PATTERN statement */
/* create the map */
proc gmap data=sample2 map=wa;
  id state county;
  choro data / nolegend anno=anno;
run;
quit;


 

 

The data in the above code is the original data. That is correct. Thank you!

ballardw
Super User

Your very first data set failed for several reasons. Had you checked it at all? You had warnings about "went to next line" meaning line length issues in the data step, the informats for countynm and data were too short and were cutting off data.

You were merging proper case county name with all caps name(in the map data); the display data should be just that: enough variables to match the ID variables and the display variables. Including MAP data points has a potential for issues. Also not that there were a number of data content and display issues as well as missing options.

 

You will need to get to the point where when someone says: Add a format statement for the variable to the Proc Gmap code. that you do not need to have the entire program rewriten.

 

 

data sample;
  infile datalines truncover; /* some lines shorter than others and reading "Grays Harbor" for the grant county data*/
  input @;
  _infile_=transtrn(_infile_,'County',' ');
  length countynm $ 25; /* to match length in Maps.Cntyname*/
  informat countynm $21.; /* some records were getting cut off*/
  informat data $9.;
  input countynm & data $9.;  
  /* determine the name of the county to merge with MAPS.CNTYNAME to
  obtain the county FIPS code */
  NumericValue = input(scan(data,3,'/'),best5.);
  countynm = upcase(countynm); /* to match the values in the Map.cntyname set*/
  datalines;
Adams County 1/2/7.3
Asotin County 1/2/2.7
Benton County 1/2/9.2
Chelan County 1/2/9.7
Clallam County 1/2/19.8
Clark County 1/2/5.8
Columbia County 1/2/7.4
Cowlitz County 1/2/5.5
Douglas County 1/2/9.5
Ferry County 1/2/12.4
Franklin County 1/2/7.3
Garfield County 1/2/3.3
Grant County 1/2/6.5
Grays Harbor County 1/2/6.5
Island County 1/2/12.2
Jefferson County 1/2/10
King County 1/2/8.5
Kitsap County 1/2/10.4
Kittitas County 1/2/8.1
Klickitat County 1/2/3.4
Lewis County 1/2/6.7
Lincoln County 1/2/10.4
Mason County 1/2/8.5
Okanogan County 1/2/11.5
Pacific County 1/2/3.4
Pend Oreille County 1/2/11
Pierce County 1/2/9.8
San Juan County 1/2/9.6
Skagit County 1/2/16.9
Skamania County 1/2/7.1
Snohomish County 1/2/12.1
Spokane County 1/2/9.9
Stevens County 1/2/12.4
Thurston County 1/2/11.6
Wahkiakum County 1/2/5.5
Walla Walla County 1/2/5.4
Whatcom County 1/2/25.9
Whitman County 1/2/5.7
Yakima County 1/2/4.5
;
run;

proc sort data=sample; by countynm;
data sample2 /*(drop=countynm) you don't want to drop this as you are attempting to display
             the value in the annotate set*/;
   merge sample maps.cntyname(where=(state=53) keep=state countynm county);
   by countynm;
run;
/* project a county map of Washington */
proc gproject data=maps.counties out=wa;
where state=53 ;
id state county;
run;
/* make the annotate macros available */
%annomac;
/* determine the visual center of the county */
%centroid(wa,center,state county);
 
/* create an annotate data set to place the label */
Proc format library=work cntlout=work.cntl;
value myrange
0  -<9.7 = '<9.7'
9.7 -high = '9.7+'
;
run;
proc sort data=sample2;
   by state county;
run;
data anno (drop=countynm data numericvalue);  /* BAD idea to have the chora data item in an annotate set*/
  merge sample2 center;
  by state county;
  retain xsys ysys '2' when 'a' function 'label' color 'black' size 1;
  length text $20;
  text=data;
  position='5';
  output;
   /* use the value for county name that you orginally dropped*/
  /* proper case to make it look nicer since we have matched everything*/
  text=Propcase(countynm);
/*  text=county_name; no such variable*/
  position='8';
  output;
run;
 
/* You can define patterns to use to color the map areas using the
   PATTERN statement */
goptions reset=all;
pattern1 color=white;
Pattern2 color=yellow;
/* NOTE: when you use MAP data as DATA, which you merged above
then you have way too many records.*/
proc sql;
   create table dataformap as
   select distinct state, county, NumericValue
   from sample2
   order by state, county;
quit;
/* create the map */ proc gmap data=dataformap map=wa; id state county; choro NumericValue / nolegend anno=anno discrete; format NumericValue myrange.; run; quit;
dding
Calcite | Level 5

You are awesome! Thank you very much!

Reeza
Super User

@dding it looks like you've edited your question? If you have a new question it's probably best to start over. Also, please mark the correct answer as the solution. 

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
  • 12 replies
  • 1441 views
  • 1 like
  • 4 in conversation