BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Kethy
Calcite | Level 5

Can someone please help me in understanding the resolving of values for ''a" in below case?

I know like for &a is usa, but the rest are quite confusing with the output that i see in sas log and the way how i understood conceptually.

Much help is appreciated if someone can explain me as to how SAS interprets here.

%let a=usa;

%let usa=america;

%let america=states;

%put &a &&a &&&a &&&&a &&&&&a &&&&&&a;

1 ACCEPTED SOLUTION

Accepted Solutions
umashankersaini
Quartz | Level 8

Hi,

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

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

%put &a;   * usa *;

%put &&a;  * usa *;

%put &&&a; * America * ;

explaination : && resolves to single & (put in reserve)  resolve &a to usa, now with reserve & sas reads &usa , result is america.

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

explaination : && 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 usa.

%put &&&&&a;

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

%put &&&&&&a;

explaination : && 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 America.

%put &&&&&&&a .... would resolve to state, because we would have three ampersand (in reserve) and &a resolve to usa. &&&usa resolve to &america and it would resolve to States.

Sorry as i have put my explanation in a lay man manner, if i hurt someone , apologies......

Regards

Uma Shanker Saini

View solution in original post

5 REPLIES 5
umashankersaini
Quartz | Level 8

Hi,

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

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

%put &a;   * usa *;

%put &&a;  * usa *;

%put &&&a; * America * ;

explaination : && resolves to single & (put in reserve)  resolve &a to usa, now with reserve & sas reads &usa , result is america.

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

explaination : && 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 usa.

%put &&&&&a;

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

%put &&&&&&a;

explaination : && 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 America.

%put &&&&&&&a .... would resolve to state, because we would have three ampersand (in reserve) and &a resolve to usa. &&&usa resolve to &america and it would resolve to States.

Sorry as i have put my explanation in a lay man manner, if i hurt someone , apologies......

Regards

Uma Shanker Saini

Tom
Super User Tom
Super User

That's a perfect answer.

NishunkSaxena
Calcite | Level 5

Marvellous answer buddy.............

Kethy
Calcite | Level 5

Awesome explanation.Thank you Uma Shanker Saini.

umashankersaini
Quartz | Level 8

Tom, Nishunk and Kethy : Thank you so much for warm appreciation....

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 3727 views
  • 8 likes
  • 4 in conversation