BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
AjayKant
Calcite | Level 5

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 .

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

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

7 REPLIES 7
Cynthia_sas
SAS Super FREQ

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

AjayKant
Calcite | Level 5

Thanks to letting me know about this.!!

NickS
SAS Employee

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

AjayKant
Calcite | Level 5

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

e044800
Obsidian | Level 7

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.

Cynthia_sas
SAS Super FREQ
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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 15404 views
  • 9 likes
  • 5 in conversation