Using Macro Variables in SCL Programs

Overview

SAS Component Language (SCL) programs are placed into the input stack, and word scanning is performed for macro triggers in the same process as in other SAS programs. Macro variable references that are outside of SUBMIT blocks are resolved before execution. Therefore, in the following example, a constant value is compared to the SCL variable Wage during SCL execution:
MAIN:
   erroroff wage;
   if wage gt &max then erroron wage;
return;
Any text within a SUBMIT block is assumed to be SAS code and is therefore ignored by the SCL compiler when the SCL program is compiled. Macro variable references within SUBMIT blocks are not resolved until the SUBMIT block executes and the SAS code within the SUBMIT block is tokenized.
When a SUBMIT block executes, SAS attempts to resolve a macro variable reference (&name) to a corresponding SCL variable. If there is no corresponding SCL variable, the reference is passed to the macro processor for lookup in the global symbol table. You can force a reference (&name) within a SUBMIT block to be passed as a macro variable reference by preceding the name with two ampersands (&&name).
Also, there are several functions and routines that enable SCL programs and the macro facility to exchange information at execution time. We examine these functions and routines.
You have already learned how to use the SYMPUT routine and the SYMGET function in a DATA step. Both the SYMPUT routine and the SYMGET function can be used in SCL programs. The syntax for each is exactly the same as it is in the DATA step.
Also, both the SYMPUT routine and the SYMGET function have numeric equivalents for use in SCL programs.

The SYMPUTN Routine

The SYMPUTN routine enables you to create a macro variable during execution of an SCL program and to assign a numeric value to it.
General form, SYMPUTN routine:
CALL SYMPUTN('macro-variable', value);
Here is an explanation of the syntax:
macro-variable
is the name of a global macro variable enclosed in single quotation marks with no ampersand. Alternatively, it is the name of an SCL variable (not enclosed in quotation marks) whose value is the name of a global macro variable.
value
is the numeric value that is assigned to macro-variable, which can be a number of the name of a numeric SCL variable.

Example

Suppose the SCL variable unitvar has a value of unit and the SCL variable unitnum has a numeric value of 200. To create a macro variable whose name is the value of unitvar (in this case, unit) and assign a value equal to the value of the SCL variable unitnum (in this case, 200) you submit the following statement within a SUBMIT block:
call symputn(unitvar, unitnum);
Similarly, to create a macro variable named unitvar and assign a numeric value of 500 to it, you submit the following statement within a SUBMIT block.
call symputn('unitvar', 500);

The SYMGETN Function

The SYMGETN function enables you to obtain the numeric value of a macro variable during execution of an SCL program.
General form, SYMGETN function:
SCL-variable = SYMGETN('macro-variable');
Here is an explanation of the syntax:
SCL-variable
is the name of a numeric SCL variable to which the value of macro-variable is assigned.
macro-variable
is the name of a global macro variable enclosed in single quotation marks with no ampersand. Alternatively, it is the name of an SCL variable (not enclosed in quotation marks) whose value is the name of a global macro variable.

Example

Suppose the SCL variable unitvar has a value of unit, the macro variable unit has a value of 200, and the macro variable unitvar has a value of 500. The first statement below creates an SCL variable named unitnum and assigns to it a value of 200. The second statement creates an SCL variable named unit and assigns it a value of 500.
unitnum=symgetn(unitvar);
unit=symgetn('unitvar'),
Note: For more information about using macro variables in SCL, see the SAS documentation for the macro language.
..................Content has been hidden....................

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