Chapter 10: Processing Macro Variables at Execution Time
Correct answer: c
Most macro functions
are handled by the macro processor before any SAS language statements
in the DATA step are executed. For example, the %LET statement and
any macro variable references (&macvar) are passed to the macro
processor before the program is compiled. In order to create or update
macro variables during DATA step execution, you use the SYMPUT routine.
Correct answer: a
To create a macro variable
and assign to it a value that is based on the value of a DATA step
variable, you use the SYMPUT routine. In the SYMPUT routine, to assign
a literal string as a macro variable name, you enclose the literal
in quotation marks. To assign a literal string as a value of the macro
variable, you enclose the literal in quotation marks.
Correct answer: d
The SYMPUT routine enables
you to assign a data set variable as the value of a macro variable.
You can also use the SYMPUT routine to create a series of related
macro variables. Because all macro variable values are character strings,
SYMPUT automatically converts any numeric value that you attempt to
assign as a value for a macro variable. In an SCL program, you must
use SYMPUTN rather than SYMPUT if you are attempting to assign a numeric
value to a macro variable.
Correct answer: b
You can use multiple
ampersands to create an indirect reference when the value of one macro
variable is the name of another. If you enclose the DATA step variable
name in quotation marks in the SYMPUT routine, the new macro variable
will have the same name as the DATA step variable rather than having
the DATA step variable's value as a name. Use the SYMGET function
to obtain the value of a macro variable during the execution of a
DATA step.
Correct answer: b
If more than four consecutive
ampersands precede a name token, rescanning continues from left to
right until no more triggers can be resolved. The Forward Re-scan
rule describes how the macro processor resolves macro variable references
that start with multiple ampersands or with multiple percent signs.
Correct answer: d
A macro variable reference
(&macvar) is resolved before any SAS language statements are sent
to the compiler. The SYMGET function enables you to obtain the value
of a macro variable during the execution of a DATA step or a PROC
SQL step. The SYMGET function can also be used to obtain the value
of a macro variable during the execution of an SCL program.
Correct answer: c
To create a macro variable
during the execution of a PROC SQL step, use the INTO clause of the
SELECT statement. In the INTO clause, you precede the name of the
macro variable with a colon.
Correct answer: c
You can use multiple
ampersands to delay the resolution of a macro variable reference.
You can also combine macro variable references in order to create
new tokens. In this example, the reference &&teach&crs
resolves to &teach3 on the first scan. On the next scan, &teach3
resolves to Forest, Mr. Peter.
Correct answer: d
You can use the SYMGET
function in an assignment statement to obtain the current value of
a macro variable and to assign that value to a DATA step variable.
The SYMGET function enables you to obtain the value of a macro variable
during execution of a DATA step, a PROC SQL step, or an SCL program.
Correct answer: c
The SYMPUT routine can
be used in either the DATA step or in an SCL program. In the DATA
step, the SYMPUT routine will perform automatic conversion on numeric
values that you attempt to assign as values for macro variables, using
the BEST12. format. In an SCL program, you should use the SYMPUTN
routine if you want to assign a numeric value as a value for a macro
variable. In a PROC SQL step, you need to use the INPUT function in
order to convert macro variable values to numeric before you compare
them to other numeric values.