Nesting symbolic variables

In some situations, you might want to store the name of a variable in another variable. For example, if you had to process two variables in the same way, you can assign their names to a third variable.

When you store the name of a variable in another variable, you are "nesting" variables.

To nest one variable in another variable, use an assignment statement with double ampersands. For example, to nest the variable &CAT in the variable &MAMMAL, code:
SET MAMMAL = &&CAT              /* result: &MAMMAL contains &CAT */
The double ampersands (&&) prevent the CLIST from performing symbolic substitution on the variable string &CAT. In the assignment statement, the CLIST removes only the first ampersand, setting &MAMMAL to the value &CAT.
It is most useful to nest variables when you have to process many variables that have similar names. For example, if you have to set &VARIABLE to different variables such as &LINE1, &LINE2, during processing, you can code many SET statements, or code the following sequence:
SET NUMBER=0
SET VARIABLE=&&LINE&NUMBER      /* Initialize &VARIABLE to &LINE0 */
DO WHILE &NUMBER<8              /* Process from &LINE1-&LINE8     */
 SET NUMBER = &NUMBER+1         /* Increase &NUMBER to create next
                                /*                  variable name */
 SET VARIABLE=&&LINE&NUMBER     /* Set &VARIABLE to next variable
                                /*                           name */
 (processing)
END
For more examples of using nested variables, see &SYSOUTLINE, and Allocating data sets to SYSPROC - the SPROC CLIST.
If you nest variables whose values contain double ampersands, the outermost variable contains the name of the innermost variable. For example, after the following statements execute, VARIABLE contains &LINE1 and DATA contains the value 430.
SET LINE1=430
SET NUMBER=1
SET VARIABLE=&&LINE&NUMBER
SET DATA=&VARIABLE