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

I found some great documentation on displaying regions inside a map at:

http://support.sas.com/rnd/datavisualization/mapsonline/html/maps/countries/us_va.html

The visual example displays the name of the region when you hover over it.  In SAS 9.2 when I hover over a region the tooltip displays numerical stuff.  I found a way to format the FIPS codes as text.  Is there a way to set what is displayed inside the tooltip so that I only see the formatted FIPS code as the region name?


/********************************************************

* This sample code will project a US state separately. *

* It expects the 2-char alpha FIPS code as input. Cut  *

* and paste this SAS code into your SAS Program Editor *

* and Submit to see sample output.                     *

* NOTES: although we are passing in the alpha code for *

*        a state, the MAPS.COUNTIES dataset contains   *

*        the numeric FIPS number for the state.        *

* stfips("&state") converts the alpha code to numeric  *

* stnamel("&state") converts the alpha code to the     *

*        long name for the state.                      *

********************************************************/

%macro stateprj(state);

data state;

set maps.counties(where=(state=stfips("&state")));

call symput('stname',stnamel("&state"));

run;

proc gproject data=state out=stateprj;

id state county;

run;

proc gmap map=stateprj data=stateprj;

id state county; choro county/discrete nolegend;

title "&stname" c="green";

pattern v=e r=300 c="blue";

;

format county cLvl.;

run;

%mend;

/*******************************************************

* submit a statement like the one below to see a map  *

* of the state of your choice.                        *

*******************************************************/

%stateprj(VA);

1 ACCEPTED SOLUTION

Accepted Solutions
Darrell_sas
SAS Employee

I think you need to talk to Tech Support.  It seems to be fixed in 9.4.  It is likely that something was fixed between 9.2 and 9.4.  And see if there is a workaround.  Tech Support should know.

View solution in original post

8 REPLIES 8
DavidPhillips2
Rhodochrosite | Level 12

This handles the county tooltip, there should be a way to lookup county name without having to use a format.  Like how state is handled.

proc format;

  /*from http://www.epa.gov/envirofw/html/codes/va.html*/

  value cLvl

  1='ACCOMACK'

  3='ALBEMARLE'

  510='ALEXANDRIA (CITY)'

  5='ALLEGHANY'

  7='AMELIA'

  9='AMHERST'

  11='APPOMATTOX'

  13='ARLINGTON'

  15='AUGUSTA'

  17='BATH'

  19='BEDFORD'

  515='BEDFORD (CITY)'

  21='BLAND'

  23='BOTETOURT'

  520='BRISTOL (CITY)'

  25='BRUNSWICK'

  27='BUCHANAN'

  29='BUCKINGHAM'

  530='BUENA VISTA (CITY)'

  31='CAMPBELL'

  33='CAROLINE'

  35='CARROLL'

  36='CHARLES CITY'

  37='CHARLOTTE'

  540='CHARLOTTESVILLE (CITY)'

  550='CHESAPEAKE (CITY)'

  41='CHESTERFIELD'

  43='CLARKE'

  560='CLIFTON FORGE (CITY)'

  570='COLONIAL HEIGHTS (CITY)'

  580='COVINGTON (CITY)'

  45='CRAIG'

  47='CULPEPER'

  49='CUMBERLAND'

  590='DANVILLE (CITY)'

  51='DICKENSON'

  53='DINWIDDIE'

  595='EMPORIA (CITY)'

  57='ESSEX'

  59='FAIRFAX'

  600='FAIRFAX (CITY)'

  610='FALLS CHURCH (CITY)'

  61='FAUQUIER'

  63='FLOYD'

  65='FLUVANNA'

  67='FRANKLIN'

  620='FRANKLIN (CITY)'

  69='FREDERICK'

  630='FREDERICKSBURG (CITY)'

  640='GALAX (CITY)'

  71='GILES'

  73='GLOUCESTER'

  75='GOOCHLAND'

  77='GRAYSON'

  79='GREENE'

  81='GREENSVILLE'

  83='HALIFAX'

  650='HAMPTON (CITY)'

  85='HANOVER'

  660='HARRISONBURG (CITY)'

  87='HENRICO'

  89='HENRY'

  91='HIGHLAND'

  670='HOPEWELL (CITY)'

  93='ISLE OF WIGHT'

  95='JAMES CITY'

  97='KING AND QUEEN'

  99='KING GEORGE'

  101='KING WILLIAM'

  103='LANCASTER'

  105='LEE'

  678='LEXINGTON (CITY)'

  107='LOUDOUN'

  109='LOUISA'

  111='LUNENBURG'

  680='LYNCHBURG (CITY)'

  113='MADISON'

  683='MANASSAS (CITY)'

  685='MANASSAS PARK (CITY)'

  690='MARTINSVILLE (CITY)'

  115='MATHEWS'

  117='MECKLENBURG'

  119='MIDDLESEX'

  121='MONTGOMERY'

  125='NELSON'

  127='NEW KENT'

  700='NEWPORT NEWS (CITY)'

  710='NORFOLK (CITY)'

  131='NORTHAMPTON'

  133='NORTHUMBERLAND'

  720='NORTON (CITY)'

  135='NOTTOWAY'

  137='ORANGE'

  139='PAGE'

  141='PATRICK'

  730='PETERSBURG (CITY)'

  143='PITTSYLVANIA'

  735='POQUOSON (CITY)'

  740='PORTSMOUTH (CITY)'

  145='POWHATAN'

  147='PRINCE EDWARD'

  149='PRINCE GEORGE'

  153='PRINCE WILLIAM'

  155='PULASKI'

  750='RADFORD (CITY)'

  157='RAPPAHANNOCK'

  159='RICHMOND'

  760='RICHMOND (CITY)'

  161='ROANOKE'

  770='ROANOKE (CITY)'

  163='ROCKBRIDGE'

  165='ROCKINGHAM'

  167='RUSSELL'

  775='SALEM (CITY)'

  169='SCOTT'

  171='SHENANDOAH'

  173='SMYTH'

  780='SOUTH BOSTON (CITY)'

  175='SOUTHAMPTON'

  177='SPOTSYLVANIA'

  179='STAFFORD'

  790='STAUNTON (CITY)'

  800='SUFFOLK (CITY)'

  181='SURRY'

  183='SUSSEX'

  185='TAZEWELL'

  810='VIRGINIA BEACH (CITY)'

  187='WARREN'

  191='WASHINGTON'

  820='WAYNESBORO (CITY)'

  193='WESTMORELAND'

  830='WILLIAMSBURG (CITY)'

  840='WINCHESTER (CITY)'

  195='WISE'

  197='WYTHE'

  199='YORK';

run;

/********************************************************

* This sample code will project a US state separately. *

* It expects the 2-char alpha FIPS code as input. Cut  *

* and paste this SAS code into your SAS Program Editor *

* and Submit to see sample output.                     *

* NOTES: although we are passing in the alpha code for *

*        a state, the MAPS.COUNTIES dataset contains   *

*        the numeric FIPS number for the state.        *

* stfips("&state") converts the alpha code to numeric  *

* stnamel("&state") converts the alpha code to the     *

*        long name for the state.                      *

********************************************************/

%macro stateprj(state);

data state;

set maps.counties(where=(state=stfips("&state")));

call symput('stname',stnamel("&state"));

run;

proc gproject data=state out=stateprj;

  id state county;

run;

data stateprj; set stateprj;

length myhtml $ 1024;

myhtml= 'title='|| quote(trim(put(county, cLvl.))||' ');

run;

proc gmap map=stateprj data=stateprj ;

id state county; choro county/discrete nolegend html = myhtml;

title "&stname" c="green";

pattern v=e r=300 c="blue";

run;

%mend;

Darrell_sas
SAS Employee

Unfortunately, there isn't an equivalent of STFIPS for counties.  And counties change names and FIPS code.  For example, Dade county Florida became Miami-Dade county.  The county name and map needed to be synchronized.

In the new MAPSGFK maps, there is a us_counties data set AND a us_counties_attr data set.  The us_counties_attr (attributes) data set has a variable that contains the county name.  That doesn't help you because you are still using 9.2 and that version cannot use MAPSGFK.

DavidPhillips2
Rhodochrosite | Level 12

The code that I posted is rather long but works for what i need.

DavidPhillips2
Rhodochrosite | Level 12

When I try to display the graph inside ods html format in Information Delivery portal 4.2.  My tooltip stops working.  Do I need to use tooltip rather than html=?  The tooltip options that I use with graphs do not seem to be available with proc gmap.  Is there a way to use template tooltips with proc gmap?

DavidPhillips2
Rhodochrosite | Level 12

Simplied code to only look at the hover part.

data maplabel;

   length function $ 8;

   retain flag 0 xsys ysys '2' hsys '3' when 'a' style 'swissb';

   set maps.uscenter(where=(fipstate(state) ne 'DC') drop=long lat);

   function='label'; text=fipstate(state); size=2.5; position='5';

   if ocean='Y' then

      do;

         position='6'; output;

         function='move';

         flag=1;

      end;

   else if flag=1 then

      do;

         function='draw'; size=.5;

         flag=0;

      end;

   output;

run;

/*****************virginia display with counties**************/

data va; set maps.counties;  if (state=51) then output; run; 

proc gproject data=va out=VAprj; id state; run;

data VAprj; set VAprj;

length myhtml $ 1024;

studentCount = ranuni (50);

myhtml= 'title=' ||  quote(propcase(trim(county))|| '0D'x || ' Student count: ' || studentCount);

run;

proc gmap map=VAprj data=VAprj ;

id county; choro studentCount / html = myhtml;

run;

quit;

DavidPhillips2
Rhodochrosite | Level 12

I found this code that works in enterprise guide but does not produce tool tips in Information Delivery Portal 4.2.  It works in enterprise guide.  My end users use Information Delivery Portal.

/*******************************************************************\

| Copyright (C) 2003 by SAS Institute Inc., Cary, NC, USA.          |

|                                                                   |

| SAS (R) is a registered trademark of SAS Institute Inc.           |

|                                                                   |

| SAS Institute does not assume responsibility for the accuracy of  |

| any material presented in this file.                              |

\*******************************************************************/

/* Using ODS HTML to allow "alt=" chart tips */

/********************************************************************

* This SAS program uses ODS to generate a map with chart tips like *

* the maps at www.sas.com/mapsonline. This program also expects     *

* SAS/Graph map datasets to be installed at your site and          *

* referenced by the libref MAPS.                                   *

********************************************************************/

/********************************************************************

* change this "path to a location in your file system" to an       *

* actual path.   This is the only line you have to change to run   *

* the program.                                                     *

********************************************************************/

%let path='mywrite location path';

/* assigns the alias ‘fileout’ to the output file.  */

filename fileout "afghanmap.html";

/* close the listing destination */

ods listing close;

/******************************************************************

* PATH= specifies the destination for all HTML and GIF files.    *

*      produced by this application.                             *

* FILE= specifies the HTML file that contains the map output.    *

******************************************************************/

/*ods html file=fileout (title="AFGHANISTAN Map")

path="&path" (url=none) style=mapstyle

nogtitle nogfootnote;*/

/* ignore previous titles. Set the graph pattern and color */

title;

pattern1 v=s c=cxFFFF99  ;

/*******************************************************************

* this datastep adds a url for each name if one exists or an alt= *

* value.                                                          *

*******************************************************************/

data ids;

length url $ 80;

set maps.AFGHANI2 ;

url = 'alt="' || trim( IDNAME ) || '" title="' || trim( IDNAME ) || '"';

run;

/* create the map using the GMAP procedure. */

proc gmap data=ids map=MAPS.AFGHANIS;

id id;

choro id / nolegend name="AFGHANIS" levels=1 coutline=black html=url;

run;

quit;

/* Close the HTML destination. */

ods html close;

/* Open the listing destination. */

ods listing;

/*ods _all_ close;*/

DavidPhillips2
Rhodochrosite | Level 12

This is similar to:

Darrell_sas
SAS Employee

I think you need to talk to Tech Support.  It seems to be fixed in 9.4.  It is likely that something was fixed between 9.2 and 9.4.  And see if there is a workaround.  Tech Support should know.

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 3496 views
  • 0 likes
  • 2 in conversation