How Macro References Are Resolved by SCL
An important point to remember when using the macro facility with SCL is that macros
and macro variable references in SCL programs are resolved when the SCL program
compiles, not when you execute the application. To further control the assignment and
resolution of macros and macro variables, use the following techniques:
• If you want macro variables to be assigned and retrieved when the SCL program
executes, use CALL SYMPUT and CALL SYMPUTN in the SCL program.
• If you want a macro call or macro variable reference to resolve when an SCL
program executes, use SYMGET and SYMGETN in the SCL program.
Referencing Macro Variables in Submit Blocks
In SCL, macro variable references are resolved at compile time unless they are in a
Submit block. When SCL encounters a name prefixed with an ampersand (&) in a
Submit block, it checks whether the name following the ampersand is the name of an
SCL variable. If so, SCL substitutes the value of the corresponding variable for the
variable reference in the submit block. If the name following the ampersand does not
match any SCL variable, the name passes intact (including the ampersand) with the
submitted statements. When SAS processes the statements, it attempts to resolve the
name as a macro variable reference
To guarantee that a name is passed as a macro variable reference in submitted
statements, precede the name with two ampersands (for example, &&DSNAME). If you
have both a macro variable and an SCL variable with the same name, a reference with a
single ampersand substitutes the SCL variable. To force the macro variable to be
substituted, reference it with two ampersands (&&).
Considerations for Sharing Macros between SCL Programs
Sharing macros between SCL programs can be useful, but it can also raise some
configuration management problems. If a macro is used by more than one program, you
must keep track of all the programs that use it so that you can recompile all of them each
time the macro is updated. Because SCL is compiled, each SCL program that calls a
macro must be recompiled whenever that macro is updated.
CAUTION:
Recompile the SCL program. If you fail to recompile the SCL program when you
update the macro, you run the risk of the compiled SCL being out of sync with the
source.
Example Using Macros in an SCL Program
This SCL program is for an example application with the fields BORROWED,
INTEREST, and PAYMENT. The program uses the macros CKAMOUNT and CKRATE
to validate values entered into fields by users. The program calculates the payment,
using values entered for the interest rate (INTEREST) and the sum of money
(BORROWED).
/* Display an error message if AMOUNT */
/* is less than zero or larger than 1000. */
%macro ckamount(amount);
Interfaces with the SAS Component Language 111