X “DEL &fileref..TMP”;
%end;
/* CMS */
%else %if &sysscp=CMS %then %do;
X “ERASE &fileref TMP A”;
%end;
%mend delfile;
Here is a call to the macro DELFILE in a PC environment that deletes a file named C:
SASSasuserDoc1.Tmp:
%delfile(c:sasSasuserDoc1)
In this program, note the use of the portable %SYSEXEC statement to carry out the
host-specific operating system commands.
Now, suppose you know your macro application is going to run on some version of
Microsoft Windows. The SYSSCPL automatic macro variable provides information
about the name of the host environment, similar to the SYSSCP automatic macro
variable. However, SYSSCPL provides more information and enables you to further
modify your macro code.
Example Using SYSPARM
Suppose the SYSPARM= system option is set to the name of a city. That means the
SYSPARM automatic variable is set to the name of that city. You can use that value to
subset a data set and generate code specific to that value. Simply by making a small
change to the command that invokes SAS (or to the configuration SAS file), your SAS
job will perform different tasks.
/* Create a data set, based on the value of the */
/* SYSPARM automatic variable. */
/* An example data set name could be MYLIB.BOSTON. */
data mylib.&sysparm;
set mylib.alltowns;
/* Use the SYSPARM SAS language function to */
/* compare the value (city name) */
/* of SYSPARM to a data set variable. */
if town=sysparm();
run;
When this program executes, you end up with a data set that contains data for only the
town that you are interested in. You can change what data set is generated before you
start your SAS job.
Now suppose you want to further use the value of SYSPARM to control what procedures
your job uses. The following macro does just that:
%macro select;
%if %upcase(&sysparm) eq BOSTON %then
%do;
proc report ... more SAS code;
title "Report on &sysparm";
run;
%end;
%if %upcase(&sysparm) eq CHICAGO %then
%do;
proc chart ... more SAS code;
Writing Portable Macros 153