Maps Online >Resources SAS logo
Feedback   

Sample Data
Sample Programs
Tools
Useful Links


/*******************************************************************\
| Copyright (C) 2002 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 generate a drillable map. */

/********************************************************************
* This SAS program uses ODS to generate a drillable map like some  *
* of the maps at www.sas.com/mapsonline. This program 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.                                                     *
********************************************************************/

/**********************************************************************
| Now make the US map which is annotated with the two letter postal
| code for each state. Each state can drill down to a map of that
| state's counties.
|
*/

%let path=location on your machine (c:\temp\us);

* Colors for each continent ;
%let CNA     = cx669966;
%let CSA     = cx336699;
%let CEUROPE = cx9966CC;
%let CAFRICA = cxFF9900;
%let CASIA   = cxFFFF99;
%let CSP     = cxCC0066;


goption reset dev=gif transparency goutmode=replace
xpixels=600 ypixels=400
ftext='-schumacher-clean-bold-r-normal-*-14-*-*-*-c-*-iso646.1991-irv';

data a;
length function $ 8;
retain flag 0 xsys ysys '2' hsys '3' when 'a';
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=.25;
flag=0;
end;
output;
run;

data us;
length url $ 128;
set maps.us2;
url = 'href="us_' || lowcase( fipstate(state) ) || '.html" alt="' ||
trim( fipnamel(state) ) || '"';
keep state url country;
file = lowcase( fipstate(state) ) || '.html';
name = trim( fipnamel(state) );
run;

ods html file="us926.html" (title="USA State Map")
path="&path" (url=none)
nogtitle nogfootnote;
title;
/* title h=.01 'US States'; */
footnote;
/* footnote h=.01 "Click on a state to see a map of the counties."; */
pattern1 v=s c=&CNA    ;
proc gmap map=maps.us data=us all;
id state;
choro country / levels=1 nolegend name='USA' html=url anno=a coutline=black;
run;
quit;

ods html close;
ods listing;
/**********************************************************************
| Now make maps of each US state.
|
| It would be good to annotate on the major cities. Each map should
| probably be projected independently from MAPS.STATES with more
| detail.
|
*/

data CntyName;
length url $ 120;
set maps.CntyName(where=(state ne 72));
url = 'alt="' || trim( CountyNm ) || ' COUNTY" title="' || trim( CountyNm ) || ' COUNTY"';
keep state county url;
run;

data _null_;
length st $ 2 name $ 40;
set US;
file 'temp.sas';

st = lowcase( fipstate( state ) );
name = fipnamel( state );
put 'ods html file="us_' st +(-1) '.html" (title="' name 'Map")';
put @10 'path="&path" (url=none)';
put @10 'nogtitle nogfootnote;';
put 'title h=.01 "' name +(-1) '";';
put 'proc gmap data=cntyname map=maps.uscounty all;';
put @3 'where state=' state ';';
put @3 'id state county;';
put @3 'choro county / nolegend name="' st +(-1) '" levels=1 coutline=black html=url;';
put @3 'run;';
put 'quit;';
run;

ods listing close;
pattern1 v=s c=&CNA    ;
footnote1 h=.01 "Hover the cursor over a county to see the name.";
footnote2 h=.01 "Use your browser's back icon see other states.";
%inc 'temp.sas'; * include all the generated gmap code ;
ods listing;




/********************************************************************
* For more information and examples relating to the ODS statement.          *
********************************************************************/