%macro javamap( /* This macro generates an html file that mimics what you get with proc gmap,
device=java. We bypass the gmap proc and generate the mapping file directly. We make used
of an html template file that has the basic structure needed for the java map applet. But we
have to fill in the key data, including the "geometry" data for each polygon, which we have
stored in SAS datasets (created by reading back a sample file generated by running proc gmap
with a gmap dataset.) These are projected (and reduced using proc reduce) coordinates that
originated in esrii shape files. See the mapimport setups in /pub/data/spatial/Tools. */
geometry=, /* Required. Name of the SAS dataset containing the geometry variable along with esriid */
sumlev=, /* If specified the macro will filter the data based on this value. So if you specify
sumlev=050 and data=sf32000x.moi the macro will generate a filter:
where sumlev='050' when accessing the data dataset. */
exitmac=, /* Optional. Specify the name of a predefined sas macro that will be invoked as part of the data step
that accesses the geometry and data datasets. It can include statements to create new
variables and/or to subset the data. E.g. it could consist of code such as this:
(macro stmt) if put(county,$cntyrpc.)ne '03' then goto cklast; Under55=sum(of age0_4--age45_54); (mend stmt)
which says only keep counties that are in RPC 03 and creates the new variable Under55.
Note that we ALWAYS NEED TO GO TO THE CKLAST
code which checks to see if we are processing the last observation so that it can do a call symput.
The value of the exitmac parm is the name of your macro (without the percent sign, of course) */
data=, /* specifies the SAS dataset containing the map variables (data to be mapped). E.g.
sf32000x.moi . A summary level filter will be applied if sumlev is specfied. */
fileout=, /* required name of output file where the map specs are written. Should be of type html.
If first character is a slash then it is the fully qualified name. Otherwise we assume
its a fileref. */
outfile=, /* alias for fileout */
template=%str(/pub/testmaps/javamap_template.html), /* identify the template file. If first character is
not a slash then it is assumed to be a fileref. */
idvar=areaname, /* variable to be passed as the "ChartId" variable to the applet. When the user
moves their cursor over the map this variables value is displayed. */
mapvars=, /* a list of numeric response variables to be passed to the applet. The first one listed is
the one that will be initially displayed. The others can be displayed by the user
from a drop-down menu. */
cmapvars=, /* it is possible, though not common, to have character-type response variables. If you have
one or more specify them in this parm. Unless mapvars is null the first element of cmapvars
will not be the default (initally displayed) map variable. */
mapvar=, /* alias for mapvars */
urlvar=, /* names a variable on the data= dataset that is suitable for use as the html option. The
value of this variables gets passed as the HTML_links entity for the map applet. It will
be encoded appropriately by the macro and should not contain the href= prefix or the
quotes. Just the URL as a simple text string. */
urldset=, /* if the urlvar variable is in a data set other than data then specify it here. The set
must have the esriid key variable and be sorted or indexed by it. It can be added to the
merge. Ignored if urlvar is not specified. If libref other than spatial is used then
invoking program should have the defining libname statement. */
height=600, /* height of the map area in pixels */
width=716, /* width of the map area in pixels */
title=%str(You Forgot to Specify the Title Parm), /* Title that displays at the top of the map & in title bar */
subtitle=, /* 2nd, smaller, title to go below main title. Optional. */
title2=, /* alias for subtitle */
keywords=, /* optional list of keyword values that will be include as meta tag in output file */
annods=, /* Name of an annotate dataset containing polygon labels to be passed . Usually its in the same
data library as the geometry dataset but with _labels instead of _geometry as the name. */
annoht=, /* provide an override to the value of the size variable for "label" function types on the annotate
dataset (annods). */
legend=true, /* specify a value of false to suppress the legend on initial map */
maplvls=6, /* number of levels displayed on the initial map */
cattype=EqualSizeLevels, /* type of categories. What are the other values? Discrete, Continuous, and ...? */
footnote=%str(Map Produced by the Missouri Census Data Center),
footnote2=%str(Generated by &pgm on &sysdate),
libref=sf32000x,path=%str(/pub/data/&libref),dset=,view=0, /* these parms id the dataset that we point
to with the dexter link at bottom of the map page. If dset parm not specified then no such link. */
debug=0);
%let _revdate=5/5/2005 1:07PM;
%put **** javamap macro, Rev. &_revdate, begins execution ****;
libname spatial clear;
libname spatial '/pub/data/spatial' access=readonly;
filename _style '/pub/testmaps/javamap_style.html';
%local errors; %let errors=0;
%*--check for and use aliases--;
%if %superq(outfile) ne %str() %then %let fileout=&outfile;
%if %superq(mapvar) ne %str() %then %let mapvars=&mapvar;
%if %superq(title2) ne %then %let subtitle=&title2;
%if &debug %then %put _local_;
%*---Make sure required parms specified---;
%if %superq(data) eq %then %do;
%let errors=1;
%put *****Required parameter data not specified*****;
%end;
%if %superq(fileout) eq %then %do;
%let errors=1;
%put *****Required parameter fileout not specified*****;
%end;
%if %superq(mapvars) eq and %superq(cmapvars) eq %then %do;
%let errors=1;
%put *****Required parameters mapvars/cmapvars (at least 1 required) not specified*****;
%end;
%if %superq(geometry) eq %then %do;
%let errors=1;
%put *****Required parameter geometry not specified*****;
%end;
%if &errors %then %goto endmac;
%*---Assign filerefs for input and output files---;
%local in out;
%if %qsubstr(%superq(template),1,1)=%str(/) %then %do;
filename template "&template";
%let in=template;
%end;
%else %let in=&template;
%if %qsubstr(%superq(fileout),1,1)=%str(/) %then %do;
filename out "&fileout";
%let out=out;
%end;
%else %let out=&fileout;
*----Step 1: Merge the geometry (geographic polygon) data with the response variable data
(and, if specified, the dataset containing the urlvar variable)
using esriid as the key----;
data unmatched tomap;
merge &geometry(in=ingeo)
&data(in=indata
%if &sumlev ne %str() %then %do;
where=(sumlev="&sumlev" )
%end;
%if %superq(urlvar) ne %str() and %superq(urldset) ne %str() %then %do;
&urldset(in=inurl keep=esriid &urlvar)
%end;
) end=last;
by esriid;
if _n_=1 then do;
%global gtitle gkeywords gmaplvls gcattype gfootnote gsubtitle glegend npolsp2;
call symput('npolsp2','0'); *--will get reassigned during cklast processing---;
*--We need to create global versions of macro parms so they will be recognized by the
resolve function in the generated data step. (This macro generates that data step but
the macro is not active when that step is actually running.)---;
call symput('gtitle',"&title");
call symput('gkeywords',"&keywords");
call symput('gmaplvls',"&maplvls");
call symput('gcattype',"&cattype");
call symput('gfootnote',"&footnote");
call symput('gfootnote2',"&footnote2");
call symput('gsubtitle',"&subtitle");
call symput('glegend',"&legend");
call symput('gidvar',"&idvar");
*** more?? ***;
end;
%if &exitmac ne %str() %then %&exitmac ;
if not (ingeo and indata) then output unmatched;
else do;
output tomap;
_npols+1;
end;
cklast:
if last then do;
_npolsp2=_npols +2 ; put _npolsp2=;
call symput('npolsp2',trim(left(put(_npolsp2,5.))));
end;
keep esriid geometry &idvar &mapvars &cmapvars &urlvar;
run;
%if &debug %then %put **After Step 1 global variables***; %put _global_;
*--Step 1.5: if the annotation dataset has more observations than the tomap set, then do a pickoff merge to create the
needed subset---;
%if %superq(annods) ne %str( ) %then %do;
data _null_; if 0 then set &annods nobs=nannos;
if 0 then set tomap nobs=ntomap;
if ntomap < nannos then subsetannos='1'; else subsetannos='0';
call symput('subsetannos',subsetannos);
stop; run;
%if &subsetannos %then %do;
proc sort data=tomap; by esriid; run;
proc sort data=&annods out=_annods; by esriid; run;
data _annods;
merge tomap(in=tomap keep=esriid) annods(in=inannods); by esriid;
if tomap and inannods;
run;
%let annods=_annods;
%end;
%end;
*-----Step 2: Read the template file and generate the output html file using data from the tomap dataset-;
data _null_;
infile &in end=last;
file &out lrecl=32500;
length _keyword $16;
if 0 then set tomap; *---to establish what variables are character, etc.---;
length _s $32500;
next:
link getnput; *<---that routine will simply read and copy any lines on file in until it encounters ## in
cols 1-2 at which point it will return back to here.---;
select(_keyword); *---here is where we do the work -- processing the special locations in the file where data
need to be plugged in.---;
when('com') ;
when('include') do;
infile '/pub/testmaps/javamap_style.html' end=eof_style;
do until (eof_style);
input; file &out; put _infile_;
end;
infile ∈
end;
when ('graph') do;
_s="";
if "&urlvar" ne " " then
_s=substr(_s,1,length(_s)-1)||' drillDownEnabled="true" drillDownMode="URL">';
put @7 _s;
end;
when ('vardefs') do;
length _varname $32 _varlabel $256 _varfmt $24;
%let mapvars=%lowcase(&mapvars);
%if %superq(mapvars) ne %str() %then %do;
array _mapvars(*) &mapvars;
do _i_=1 to dim(_mapvars);
call vname(_mapvars(_i_),_varname);
call label(_mapvars(_i_),_varlabel);
_varlabel=tranwrd(_varlabel,'&','&');
_varfmt= vformat(_mapvars(_i_));
_s='';
put @7 _s;
if _i_=1 then _mapvar1=_varname;
end;
_nmapvars=_i_-1;
%end;
%if %superq(cmapvars) ne %str() %then %do;
array _cmapvars(*) &cmapvars;
do _i_=1 to dim(_cmapvars);
call vname(_cmapvars(_i_),_varname);
call label(_cmapvars(_i_),_varlabel);
_varlabel=tranwrd(_varlabel,'&','&');
_varfmt= vformat(_cmapvars(_i_));
_s='';
put @7 _s;
if _i_=1 and "&mapvars"=" " then _mapvar1=_varname;
end;
_ncmapvars=_i_-1;
%end;
*--finally put the defn for the id variable--;
call label(&idvar,_varlabel); _varfmt=vformat(&idvar);
_varlabel=tranwrd(_varlabel,'&','&');
_s='';
put @7 _s;
%if &urlvar ne %str() %then %do;
_s='';
put @7 _s;
%end;
end;
when('values') do; *---This is the big one------;
retain _xmlparmno 2;
do until(_outofdata);
set tomap end=_outofdata;
_s='';
put @5 _s;
_lengeo=length(geometry);
_i=1;
put @5 '';
do until(_i > _lengeo);
_s=''||trim(substr(geometry,_i,80))||'';
put @10 _s; _i=_i+80;
end;
put @5 '';
%if %superq(mapvars) ne %str() %then %do;
do _i_=1 to dim(_mapvars); **_nmapvars;
if _mapvars(_i_) ne . then _s=''||trim(left(put(_mapvars(_i_),best12.)))||'';
else _s='';
put @12 _s;
end;
%end;
%if %superq(cmapvars) ne %str() %then %do;
do _i_=1 to _ncmapvars;
_s=''||left(trim(_cmapvars(_i_)))||'';
put @12 _s;
end;
%end;
_s=''||left(trim(&idvar))||'';
put @12 _s;
%if &urlvar ne %str() %then %do;
length _urlvaredit $200;
_urlvaredit=tranwrd(&urlvar,'&','&');
_s='href="'||trim(_urlvaredit)||'"';
put @12 _s;
%end;
put @7 ' ''>';
_xmlparmno+1;
end; *---loop to read the map data and generate specs---*;
end; *---when ('values') processing---;
when('rollvars') do;
%if &urlvar ne %str() %then %do;
_s='';
put @12 _s;
%end;
%if %superq(mapvars) ne %str() %then %do;
_varname="%scan(&mapvars,1)";
_s='';
put @12 _s;
_s=
resolve('');
put @12 _s;
%end;
%else %if %superq(cmapvars) ne %str() %then %do;
%*---Here is the code to define rolls for character type variables (cmapvars)---;
_varname="%scan(&cmapvars,1)";
_s=''||
' ';
put @12 _s;
%end;
end;
when('annotations') do;
%if %superq(annods) ne %then %do; *---generate annotations using the specified annotate dataset--;
do until(_outofannos);
set &annods end=_outofannos; where function='label';
if upcase(color)='XX000000' then color='CX000000';
%if &annods ne %str() and %quote(&annoht) ne %str() %then %do;
size=&annoht;
%end;
**;
_s='';
put @7 _s;
end;
%end;
end;
when('dexter') do;
if "&dset" ne " " then _s='Invoke Dexter to access '||"&libref..&dset.";
else _s=' ';
put @7 _s;
end;
when('eof') do;
file log; put '*****Processing Completed******';
stop;
end;
otherwise do;
geometry=" "; *<---to save long display triggered by setting _error_ to 1 here--;
error 'Keyword ' _keyword ' is not recognized************** ';
end;
end; *--select---;
goto next;
return;
getnput:
input;
if _infile_=:'##' then do;
_keyword=lowcase( scan(substr(_infile_,3),1,' '));
return;
end;
_infile_=resolve(_infile_); *--thus, &title gets replaced with its value, for example-;
put _infile_;
if not last then goto getnput;
_keyword='eof'; return;
run;
%endmac:
%mend javamap;