I like to know about the processing of working of this SAS variable .
I have three macro variable .
%let x=y ;
%let y=z ;
%let z=x ;
%put the result8 : &&&&&&&&x ;
%put the result9 : &&&&&&&&&x ;
the result is
112 %put the result8 : &&&&&&&&x ;
SYMBOLGEN: && resolves to &.
SYMBOLGEN: && resolves to &.
SYMBOLGEN: && resolves to &.
SYMBOLGEN: && resolves to &.
SYMBOLGEN: && resolves to &.
SYMBOLGEN: && resolves to &.
SYMBOLGEN: && resolves to &.
SYMBOLGEN: Macro variable X resolves to y
the result8 : y
113 %put the result9 : &&&&&&&&&x ;
SYMBOLGEN: && resolves to &.
SYMBOLGEN: && resolves to &.
SYMBOLGEN: && resolves to &.
SYMBOLGEN: && resolves to &.
SYMBOLGEN: Macro variable X resolves to y
SYMBOLGEN: && resolves to &.
SYMBOLGEN: && resolves to &.
SYMBOLGEN: && resolves to &.
SYMBOLGEN: Macro variable Y resolves to z
the result9 : z
I like to know how they are processing this ....
Can some one help me to understand .
Hi, there are two things you should read about in the macro documentation: the forward scan rule and the rescan rule. The explanation is quite straightforward and the difference in the final resolution of your multiple ampersands is explained by what you see in the SYMBOLGEN results -- if you first understand those two rules.
I posted a long explanation already in the forum, which you might find by searching. I think there were others, this is the discussion I remember:
I hope these suggestions get you started. In actual production work, over many years, I have *NEVER* needed to use so many ampersands in an indirect reference to a macro variable. Perhaps other users have different insights, but I suggest reading the doc and then doing some paper "desk checking" on how the two rules work.
cynthia
Hi, there are two things you should read about in the macro documentation: the forward scan rule and the rescan rule. The explanation is quite straightforward and the difference in the final resolution of your multiple ampersands is explained by what you see in the SYMBOLGEN results -- if you first understand those two rules.
I posted a long explanation already in the forum, which you might find by searching. I think there were others, this is the discussion I remember:
I hope these suggestions get you started. In actual production work, over many years, I have *NEVER* needed to use so many ampersands in an indirect reference to a macro variable. Perhaps other users have different insights, but I suggest reading the doc and then doing some paper "desk checking" on how the two rules work.
cynthia
Thanks to letting me know about this.!!
Hi Ajay,
Cynthia's post covers all you need to know to understand what is going on as pairs of ampersands and the macro variables resolve, but to make it more explicit for your example, the resolutions after each scan are as follows:
Example 1
Before first scan &&&&&&&&x
After first scan &&&&x
After second scan &&x
After third scan &x
After final scan y
In this example, we started with 8 ampersands before the x, and so the x does not resolve with an ampersand until the final scan.
Example 2
Before first scan &&&&&&&&&x
After first scan &&&&y
After second scan &&y
After third scan &y
After final scan z
In this example, as we started with an odd number of ampersands, the final ampersand pairs with the x and resolves to y during the first scan. The y is then untouched until the final scan where it resolves to z.
Nick
This is what i understand by processing the code ...
aha its seems lots of person think like ..
I break it even and odd pair and then starts processing code, its really great to know the exact algorithms about the processing of macro variable.
well thx all guys,,,
Hi Niks
Thanks for the reply.. i also have one iproblem which is tough to understand ..
this is what the actual problem is
%let p = 1;
%let L1 = 50;
%let w50 = XYZ;
%put 'Why the value not resolved as XYZ : - '&&&w&&L&p.;
Before Resolution: &&&w&&L&p.
first scan: &&w&L1 (Here &W gets a warning as its not resolved)
second scan: &w50
the value caomes as &w50 in log.. i am ok with this if the below example also does the same but its not doing it.
%let b120 = 5;
%let b5 = 1000;
%let a= 20;
%put 'The value is resolving :- ' &&&b1&a;
Before Resolution: &&&b1&a
first scan: &&b120 (here &b1 should also give a warning like above example but it didnt give any warning and here i am confused)
second scan: &b120
Now it prints a value of macro variable b120 = 5 in the log.
Hi Ajay,
for more clarification, Kindly refer to :
https://communities.sas.com/message/172742
or
http://sascertguru.blogspot.com.au/2014/09/multilevel-referencing-of-macro-in-sas.html
Regards
Uma Shanker Saini
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.