Reputation: 2927
Can someone give me an example of how indirect references to macro variables work and why they are used? I am still confused why indirect references are even required when you can just use a direct reference to a macro variable.
Upvotes: 1
Views: 801
Reputation: 63434
Indirect references are used when you need to generate the reference through code, typically macro code (as a direct reference can usually be created through other code). For example:
%let n1=5;
%let n2=3;
%macro doit(whichn=);
%put &&n&whichn..;
%mend doit;
%doit(whichn=1);
%doit(whichn=2);
You often use this in macro loops, such as
%do x=1 to 2;
%put &&n&x..;
%end;
which cycles through n1 and n2.
Upvotes: 2