Multilevel Referencing Of Macro In SAS - &&&&&&&& MACRO VARIABLE

Hi,

We can use any number of ampersands (&) in an indirect macro variable reference.

SAS resolves the entire reference from left to right. If a pair (double) of ampersands (&&) is encountered, the pair (double) is resolved to single ampersand, then the next part of the reference is processed.

Suppose we have following macro variables:

%let a=UMA;

%let UMA=SHANKER;

%let SHANKER=SAINI;



And we are going to check the output of the following PUT statements with multiple macro variables.

%put &a;

 %put &&a;

%put &&&a;

%put &&&&a;

%put &&&&&a;

%put &&&&&&a;

%put &&&&&&&a;



And output would be something like this:

%put &a;   * UMA *;

%put &&a;  * UMA *;

%put &&&a; * SHANKER * ;


 Explanation: && resolves to single & (put in reserve)  resolve &a to UMA, now with reserve & sas reads &UMA , result is SHANKER.

%put &&&&a; * UMA . pairing && and && comes to && resolves to & *;

Explanation: && resolves to single & (put in reserve) again && resolve to single & (put in reserve), now we have only a, no execution. in reserve we have && which is &a. again result is UMA.

%put &&&&&a;

Explanation: && resolves to single & (put in reserve) again && resolve to single & (put in reserve), now we have &a, resolve to UMA. In reserve we have two ampersand, which is one (&) and now it is &UMA, resolve to SHANKER.

%put &&&&&&a;

Explanation: && resloves to single & (put in reserve) again && resolve to single & (put in reserve) , && resolve to single & (put in reserve), now we have only a , no execution. In reserve we have &&& so again result is SHANKER.

%put &&&&&&&a;

Explanation: Would resolve to SAINI, because we would have three ampersand (in reserve) and &a resolve to UMA. &&&UMA resolve to &SHANKER and it would resolve to SAINI.

6 comments:

  1. Thanks for another excellent article. Where else could anyone get that type of information in such a perfect way of writing? I’ve a presentation next week, and I am on the look for such info.

    ReplyDelete
  2. I just want to say I’m all new to blogging and site-building and honestly loved you’re web-site. Almost certainly I’m likely to bookmark your website . You definitely have excellent well written articles. Cheers for sharing with us your website page.

    ReplyDelete
  3. Thanks for sharing the good information..

    ReplyDelete
  4. Hey.... Thanks for appreciation... it would boost my energy for new posts...

    ReplyDelete
  5. Hi, of course this article is in fact good and I have learned lot of things from it on the topic of blogging.
    thanks.

    ReplyDelete