The macro variable references shown
so far have been direct macro references that begin with one ampersand:
&
name. However, it is also
useful to be able to indirectly reference macro variables that belong
to a series so that the name is determined when the macro variable
reference resolves. The macro facility provides indirect macro variable
referencing, which enables you to use an expression (for example,
CITY&N) to generate a reference to one of a series of macro variables.
For example, you could use the value of macro variable N to reference
a variable in the series of macro variables named CITY1 to CITY20.
If N has the value 8, the reference would be to CITY8. If the value
of N is 3, the reference would be to CITY3.
Although for this example
the type of reference that you want is CITY&N, the following example
will not produce the results that you expect, which is the value of
&N appended to CITY:
%put &city&n; /* incorrect */
This code produces a
warning message saying that there is no macro variable CITY because
the macro facility has tried to resolve &CITY and then &N
and concatenate those values.
When you use an indirect
macro variable reference, you must force the macro processor to scan
the macro variable reference more than once and resolve the desired
reference on the second, or later, scan. To force the macro processor
to rescan a macro variable reference, you use more than one ampersand
in the macro variable reference. When the macro processor encounters
multiple ampersands, its basic action is to resolve two ampersands
to one ampersand. For example, for you to append the value of &N
to CITY and then reference the appropriate variable name, do the following:
%put &&city&n; /* correct */
If &N contains 6,
when the macro processor receives this statement, it performs the
following steps:
-
-
-
-
returns to the beginning
of the macro variable reference, &CITY6, starts resolving from
the beginning again, and prints the value of CITY6