Search notes:

SAS macro variables: indirect reference (via ampersand ampersand ampersand)

One, two and three ampersands

&var_foo resolves to the value of the macro variable named var_foo.
in &&var_foo, && first resolves to a single &, so &&var_foo also resolves to the value of var_foo.
However, in &&&var_foo, the first two ampersands (&&) resolve to a single ampersand and the following &var_foo (as usual) resolves to the value of var_foo, resulting in &var_value which, if var_foos_value is set, to the value of var_foos_value.
Thus, it's possible to reference another variable with three ampersands.
%let fourty_two = 42;
%let number     = fourty_two;

%put The number &number is  &&number; /* The number fourty_two is  fourty_two */
%put The number &number is &&&number; /* The number fourty_two is 42          */

* ------------------- ;

%let germanone=eins;
%let germantwo=zwei;
%let germanthree=zwei;

%let frenchone=un;
%let frenchtwo=deux;
%let frenchthree=trois;

%let lang=french;
%let num=two;

%put In &lang, &num is &&&lang# /* In french, two is deux */
Github repository about-SAS, path: /macro-processor/indirect-reference.sas

Simulating arrays

With this technique, it is possible to simulate arrays with SAS Macros
/* http://www2.sas.com/proceedings/forum2008/045-2008.pdf */
%let var1 = one;
%let var2 = two;
%let var3 = three;

%macro showVarValues;
   %do varNum = 1 %to 3;
       %put The value of var&varNum is &&var&varNum;
   %end;
%mend showVarValues;

%showVarValues
/*
The value of var1 is one
The value of var2 is two
The value of var3 is three
*/
Github repository about-SAS, path: /macro-processor/variables/simulate-arrays.sas
See also SAS macros for array processing

See also

macro variables

Index