SAS : Single, Double, Triple Ampersand Macro Variables

Deepanshu Bhalla 19 Comments ,

This tutorial explains how single (&), double (&&) and Triple (&&&) ampersand macro variables are resolved in SAS.

Example
%let x=temp;
%let n=3;
%let x3=result;
%let temp3 = result2;
Check how multiple ampersand macro variables work -
%put &x&n;
%put &&x&n;
%put &&&x&n;
Rule :
The scanner reads from left to right.
  1. &x&n : Macro variable X resolves first to temp and then N resolves to 3. Output : temp3
  2. &&x&n : Two ampersands (&&) resolves to one ampersand (&) and scanner continues and then N resolves to 3 and then &x3 resolves to result. Output : result
  3. &&&x&n : First two ampersands (&&) resolves to & and then X resolves to temp and then N resolves to 3. In last, &temp3 resolves to result2. Output : result2
SAS : Ampersand Macro Variables
Ampersand Macro Variables
Related Posts
Spread the Word!
Share
About Author:
Deepanshu Bhalla

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has over 10 years of experience in data science. During his tenure, he worked with global clients in various domains like Banking, Insurance, Private Equity, Telecom and HR.

19 Responses to "SAS : Single, Double, Triple Ampersand Macro Variables"
  1. well explained...thank you

    ReplyDelete
  2. Great stuff...keep posting

    ReplyDelete
  3. Very good stuff, really helps me a lot! Thank you very much!

    ReplyDelete
  4. Great explanation! Thank you!

    ReplyDelete
  5. amazing explanation. totally appreciate you effort i building these examples. Hats off.

    ReplyDelete
  6. what if I have &&&&&&&&&x&n ? can you please explain ?

    ReplyDelete
    Replies
    1. &&&&&&&&&x&n will give you result2

      Delete
  7. Crystal Clear..!!

    ReplyDelete
  8. very good explanation

    ReplyDelete
  9. succinct and clear. Well done.

    ReplyDelete
  10. Very well Explained...Really appreciate your efforts!!
    Just have one question:
    I didn't get in which situation double and triple ampersand is used.
    I mean,
    Why to use double or triple ampersand to get value of another variable? if it is possible to get value of particular variable using varname and single ampersand.

    ReplyDelete
Next → ← Prev