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;
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
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
That's a perfect answer.
Marvellous answer buddy.............
Awesome explanation.Thank you Uma Shanker Saini.
Tom, Nishunk and Kethy : Thank you so much for warm appreciation....
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.