DATA Step, Macro, Functions and more

multiple ampersand(&& ) processing

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 11
Accepted Solution

multiple ampersand(&& ) processing

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 .


Accepted Solutions
Solution
‎01-16-2014 11:04 AM
SAS Super FREQ
Posts: 8,745

Re: multiple ampersand(&& ) processing

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

View solution in original post


All Replies
Solution
‎01-16-2014 11:04 AM
SAS Super FREQ
Posts: 8,745

Re: multiple ampersand(&& ) processing

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

Occasional Contributor
Posts: 11

Re: multiple ampersand(&& ) processing

Thanks to letting me know about this.!!

SAS Employee
Posts: 2

Re: multiple ampersand(&& ) processing

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

Occasional Contributor
Posts: 11

Re: multiple ampersand(&& ) processing

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,,,

Occasional Contributor
Posts: 13

Re: multiple ampersand(&& ) processing

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.

SAS Super FREQ
Posts: 8,745

Re: multiple ampersand(&& ) processing

Hi:
You added a new question in the middle of a 2 year old posting. I almost did not find it. Please start a new post and just put a link to the old post. The same answer to the original question is the answer to your question. You are not using the multiple ampersands correctly and need to experiment with macro variable resolution in order to "stop" resolution at &b1, you need to distinguish where &b1 ends, by terminating the macro variable reference with a . (period or dot). Please read the macro documentation and some of the many papers on macro variable resolution.

cynthia
Frequent Contributor
Posts: 116

Re: multiple ampersand(&& ) processing

☑ This topic is solved.

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

Discussion stats
  • 7 replies
  • 3268 views
  • 8 likes
  • 5 in conversation