The NOMINOPERATOR argument specifies that the macro processor does not
recognize the mnemonic IN and the special character # as logical operators when
evaluating arithmetic or logical expressions during the execution of the macro.
The setting of this argument overrides the setting of the MINOPERATOR global
system option.
PARMBUFF
assigns the entire list of parameter values in a macro call, including the
parentheses in a name-style invocation, as the value of the automatic macro
variable SYSPBUFF. Using the PARMBUFF option, you can define a macro that
accepts a varying number of parameter values.
If the macro definition includes both a set of parameters and the PARMBUFF
option, the macro invocation causes the parameters to receive values. It also
causes the entire invocation list of values to be assigned to SYSPBUFF.
To invoke a macro defined with the PARMBUFF option in a windowing
environment or interactive line mode session without supplying a value list, enter
an empty set of parentheses or more program statements after the invocation.
This action indicates the absence of a value list, even if the macro definition
contains no parameters.
SECURE | NOSECURE
causes the contents of a macro to be encrypted when stored in a stored compiled
macro library. This feature enables you to write secure macros that will protect
certain intellectual property that is contained in the macros. Use SECURE to
secure whole segments, for example entire DATA and PROC steps. Do not use
SECURE to store code fragments or to store passwords. The macros are secured
using the Encryption Algorithm Manager.
A NOSECURE option has been implemented to aid in the global edit of a source
file or library to turn on security. For example, when you are creating several
macros that will need to be secure. When creating the macros, use the
NOSECURE option. When all macros are completed and ready for production,
you can do a global edit and change NOSECURE to SECURE.
If you use the SECURE and SOURCE options on a macro, no output is produced
when you use the %COPY statement. The following NOTE is written to the SAS
log:
NOTE: The macro %name was compiled with the SECURE
option. No output will be produced for this %COPY
statement.
STMT
specifies that the macro can accept either a name-style invocation or a statement-
style invocation. Macros defined with the STMT option are sometimes called
statement-style macros.
The IMPLMAC system option must be in effect to use statement-style macro
invocations. If IMPLMAC is in effect and you have defined a statement-style
macro in your program, the macro processor scans the first word of every SAS
statement to see whether it is a statement-style macro invocation. When the
NOIMPLMAC option is in effect, the macro processor treats only the words
following the % symbols as potential macro invocations. If the IMPLMAC
option is not in effect, you still can use a name-style invocation for a macro
defined with the STMT option.
%MACRO Statement 327
SOURCE
SRC
combines and stores the source of the compiled macro with the compiled macro
code as an entry in a SAS catalog in a permanent SAS library. The SOURCE
option requires that the STORE option and the MSTORED option be set. You
can use the SASMSTORE= option to identify a permanent SAS library. You can
store a macro or call a stored compiled macro only when the MSTORED option
is in effect. (For more information, see “Storing and Reusing Macros” on page
115.)
Note: The source code saved by the SOURCE option begins with the %MACRO
keyword and ends with the semi-colon following the %MEND statement.
CAUTION:
The SOURCE option cannot be used on nested macro definitions (macro
definitions contained within another macro).
STORE
stores the compiled macro as an entry in a SAS catalog in a permanent SAS
library. Use the SAS system option SASMSTORE= to identify a permanent SAS
library. You can store a macro or call a stored compiled macro only when the
SAS system option MSTORED is in effect. (For more information, see “Storing
and Reusing Macros” on page 115.)
Details
The %MACRO statement begins the definition of a macro, assigns the macro a name,
and can include a list of macro parameters, a list of options, or both.
A macro definition must precede the invocation of that macro in your code. The
%MACRO statement can appear anywhere in a SAS program, except within data lines.
A macro definition cannot contain a CARDS statement, a DATALINES statement, a
PARMCARDS statement, or data lines. Use an INFILE statement instead.
By default, a defined macro is an entry in a SAS catalog in the Work library. You can
also store a macro in a permanent SAS catalog for future use. However, in SAS 6 and
earlier, SAS does not support copying, renaming, or transporting macros.
You can nest macro definitions, but doing so is rarely necessary and is often inefficient.
If you nest a macro definition, then it is compiled every time you invoke the macro that
includes it. Instead, nesting a macro invocation inside another macro definition is
sufficient in most cases.
Examples
Example 1: Using the %MACRO Statement with Positional
Parameters
In this example, the macro PRNT generates a PROC PRINT step. The parameter in the
first position is VAR, which represents the SAS variables that appear in the VAR
statement. The parameter in the second position is SUM, which represents the SAS
variables that appear in the SUM statement.
%macro prnt(var,sum);
proc print data=srhigh;
var &var;
sum ∑
run;
%mend prnt;
328 Chapter 19 Macro Statements
In the macro invocation, all text up to the comma is the value of parameter VAR; text
following the comma is the value of parameter SUM.
%prnt(school district enrollmt, enrollmt)
During execution, macro PRNT generates the following statements:
PROC PRINT DATA=SRHIGH;
VAR SCHOOL DISTRICT ENROLLMT;
SUM ENROLLMT;
RUN;
Example 2: Using the %MACRO Statement with Keyword
Parameters
In the macro FINANCE, the %MACRO statement defines two keyword parameters,
YVAR and XVAR, and uses the PLOT procedure to plot their values. Because the
keyword parameters are usually EXPENSES and DIVISION, default values for YVAR
and XVAR are supplied in the %MACRO statement.
%macro finance(yvar=expenses,xvar=division);
proc plot data=yearend;
plot &yvar*&xvar;
run;
%mend finance;
To use the default values, invoke the macro with no parameters.
%finance()
or
%finance;
The macro processor generates this SAS code:
PROC PLOT DATA=YEAREND;
PLOT EXPENSES*DIVISION;
RUN;
To assign a new value, give the name of the parameter, an equal sign, and the value:
%finance(xvar=year)
Because the value of YVAR did not change, it retains its default value. Macro
execution produces this code:
PROC PLOT DATA=YEAREND;
PLOT EXPENSES*YEAR;
RUN;
Example 3: Using the %MACRO Statement with the PARMBUFF
Option
The macro PRINTZ uses the PARMBUFF option to enable you to input a different
number of arguments each time you invoke it:
%macro printz/parmbuff;
%let num=1;
%let dsname=%scan(&syspbuff,&num);
%do %while(&dsname ne);
proc print data=&dsname;
run;
%let num=%eval(&num+1);
%MACRO Statement 329
%let dsname=%scan(&syspbuff,&num);
%end;
%mend printz;
This invocation of PRINTZ contains four parameter values, PURPLE, RED, BLUE, and
TEAL although the macro definition does not contain any individual parameters:
%printz(purple,red,blue,teal)
As a result, SAS receives these statements:
PROC PRINT DATA=PURPLE;
RUN;
PROC PRINT DATA=RED;
RUN;
PROC PRINT DATA=BLUE;
RUN;
PROC PRINT DATA=TEAL;
RUN;
Example 4: Using the %MACRO Statement with the SOURCE Option
The SOURCE option combines and stores the source of the compiled macro with the
compiled macro code. Use the %COPY statement to write the source to the SAS log. For
more information about viewing or retrieving the stored source, see “%COPY
Statement” on page 306.
/* commentary */ %macro foobar(arg) /store source
des="This macro does not do much";
%put arg = &arg;
* this is commentary!!!;
%* this is macro commentary;
%mend /* commentary; */; /* Further commentary */
NOTE: The macro FOOBAR completed compilation without errors.
%copy foobar/source;
The following results are written to the SAS log:
%macro foobar(arg) /store source
des="This macro does not do much";
%put arg = &arg;
* this is commentary!!!;
%* this is macro commentary;
%mend /* commentary; */;
Example 5: Using the %MACRO Statement with the STORE and
SECURE Options
The SECURE option can be used only in conjunction with the STORE option. The
following example demonstrates the use of the STORE and an implied NOSECURE
option to create a macro that is stored in plain text.
options mstored sasmstore=mylib;
libname mylib "SAS-library";
%macro nonsecure/store; /* This macro is stored in plain text */
data _null_;
x=1;
put "This data step was generated from a non-secure macro.";
run;
%mend nonsecure;
%nonsecure
330 Chapter 19 Macro Statements
filename maccat catalog 'mylib.sasmacr.nonsecure.macro';
data _null_;
infile maccat;
input;
list;
run;
The following example demonstrates the use of the STORE and SECURE options to
create a macro that is encrypted.
options mstored sasmstore=mylib;
libname mylib "SAS-library";
%macro secure/store secure; /* This macro is encrypted */
data _null_;
x=1;
put "This data step was generated from a secure macro.";
run;
%mend secure;
%secure
filename maccat catalog 'mylib.sasmacr.secure.macro';
data _null_;
infile maccat;
input;
list;
run;
%MEND Statement
Ends a macro definition.
Type: Macro statement
Restriction: Allowed in macro definitions only
Syntax
%MEND <macro-name> ;
Required Argument
macro-name
names the macro as it ends a macro definition. Repeating the name of the macro is
optional, but it is useful for clarity. If you specify macro-name, the name in the
%MEND statement should match the name in the %MACRO statement; otherwise,
SAS issues a warning message.
Example: Ending a Macro Definition
%macro disc(dsn);
data &dsn;
set perm.dataset;
where month="&dsn";
run;
%mend disc;
%MEND Statement 331
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset