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

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3769 views
  • 8 likes
  • 4 in conversation