Maps Online >Resources SAS logo
Feedback    FAQ   

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.                              |
\*******************************************************************/

/* About MACRO used in sample programs for MAPS  */

/********************************************************************
* SAS macro language allows you to run SAS programs in a batch-like*
* mode. This is useful for SAS code that needs to be executed      *
* repeatedly, but with new parameters.                             *
********************************************************************/

/*******************************************************
* this program creates a simple map of each country.  *
*******************************************************/

/*******************************************************
* Using MPRINT will display the resulting SAS Code in *
* the SAS LOG window.                                 *
*******************************************************/
options MPRINT fmtsearch=(sashelp.mapfmts);

/*******************************************************
* A macro begins with %macro, followed by a name(show)*
* and ends with %mend.The macro may or may not contain*
* parameters or variables, separated by commas within *
* (). These parameters contain the values for those   *
* variables that are replaced with each execution.This*
* is only one example of how parameters can be        *
* specified. Refer to the SAS Macro documentation     *
* for alternate methods. This macro expects nine (9)  *
* parameters, in order, when it is called.            *
*******************************************************/
%macro show(cntry,dsn,dsn2,lid1,lid2,type,legend,mode,n);

/*******************************************************
* This legend statement uses 2 macro variables        *
* prefixed by ampersand(&). The first time the macro  *
* is called, the legend statement below resolves to:  *
* legend label=none mode=share across=3 origin=(0,0)  *
*******************************************************/

/**** this legend statement may or may not be used in this map ****/
legend label=none mode=&mode  across=&n origin=(0,0);

/*******************************************************
* This PROC statement uses 4 macro variables prefixed *
* by ampersand(&). This statement resolves to         *
* proc gmap map=maps.ALGERIA data=maps.ALGERIA2       *
* proc gmap map=maps.NZ data=maps.NZ2                 *
*******************************************************/
proc gmap map=&dd1..&dsn data=&dd2..&dsn2;

/*******************************************************
* This ID statement uses 1 macro variables prefixed   *
* by ampersand(&). This statement resolves to         *
* id id;                                              *
*******************************************************/
id &lid1;

/*******************************************************
* This CHORO statement uses 3 macro variables prefixed*
* by ampersand(&). This statement resolves to         ***********
* choro idname/discrete nolegend coutline=graycc name="ALGERIA" *
* choro idname/discrete nolegend coutline=graycc name="NZ"      *
*****************************************************************/
choro &lid2/discrete &legend coutline=graycc name="&dsn";

format country glcnsu.;

/*******************************************************
* This TITLE statement uses 1 macro variables prefixed*
* by ampersand(&). This statement resolves to         *
* title "ALGERIA"   title "NEW ZEALAND"               *
*******************************************************/
title "&cntry";

run;

/*******************************************************
* %mend ends the block of macro code.                 *
*******************************************************/
%mend;

/*******************************************************
* %let is used to assign values to the macro variables*
* dd1 and dd2. It can be done this way if the values  *
* will not change as often as those passed when the   *
* macro is called.                                    *
*******************************************************/
%let dd1=maps;
%let dd2=maps;

pattern1 v=s c=cxFF9900 r=100;

goptions dev=gif transparency gaccess=gsasfile goutmode=replace
xpixels=600 ypixels=400 ftext=simplex
gunit=pct htext=.15in colors= ctext=black;

FOOTNOTE "variable: idname (administrative division)";

/*******************************************************
* This statement calls the macro by name(show) and    *
* gives values for each variable specified at the     *
* beginning of the macro.  You can leave a value blank*
* but if one is expected, your program should have a  *
* condition to check for missing or you may receive   *
* errors.                                             *
*******************************************************/
filename gsasfile  "algeria.gif";
%show( ALGERIA ,ALGERIA ,ALGERIA2 ,id,idname,solid,nolegend,share,3);

/*******************************************************
* The macro code ended with %mend. When you submit the*
* macro it gets compiled but is not executed until a  *
* statement like the one below is submitted.          *
* You can submit several such statements without      *
* having to resubmit the block of macro code. %str()  *
* is used to group all words that form a single value *
*******************************************************/
filename gsasfile  "nz.gif";
%show(%str(NEW ZEALAND) ,NZ ,NZ2 ,id,region,solid,%str(legend=legend),share,1);

/*******************************************************
* For more information refer to your documentation on *
* the SAS Macro Language or visit the following sites:*
* Training Courses , Technical Support FAQ on Macros        *
*******************************************************/