DATA Step, Macro, Functions and more

macro resolving issue

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 14
Accepted Solution

macro resolving issue

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;


Accepted Solutions
Solution
‎06-30-2013 03:18 PM
Frequent Contributor
Posts: 118

Re: macro resolving issue

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


All Replies
Solution
‎06-30-2013 03:18 PM
Frequent Contributor
Posts: 118

Re: macro resolving issue

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

Super User
Super User
Posts: 7,060

Re: macro resolving issue

Posted in reply to umashankersaini

That's a perfect answer.

Occasional Contributor
Posts: 12

Re: macro resolving issue

Posted in reply to umashankersaini

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

Occasional Contributor
Posts: 14

Re: macro resolving issue

Posted in reply to umashankersaini

Awesome explanation.Thank you Uma Shanker Saini.

Frequent Contributor
Posts: 118

Re: macro resolving issue

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

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

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