BookmarkSubscribeRSS Feed
nimmy_mj
Calcite | Level 5

Hi, I have the below code:

%let a=b;
%let b=c;
%let c=a;

%let d=&c; %let e=&&c; %let f=&&&c; %let g=&&&&c; %let h=&&&&&c; %let i=&&&&&&c;

data test;
check="&d";output;
check="&e";output;
check="&f";output;
check="&g";output;
check="&h";output;check="&i";output;
run;

 

d resolves to a

e resolves to a

f resolves to b

g resolves to a

h resolves to b

I resolves to b

 

Could you please explain how this is happening? According to my logic, g should resolve to b and h should resolve to c and I to c.

 

If there is a diagrammatical representation, it will be helpful.

4 REPLIES 4
Shmuel
Garnet | Level 18

Pay attention that any && are in first step replaced by &.

 

&&&X = (&&) &X - (1) resolve &X then resolve &(resolved value)

 

&&&&X = (&&)(&&)x = &&X = &X

 

I hope that explains the behavior.

Tom
Super User Tom
Super User

Turn the SYMBOLGEN option and see for yourself what is happening.

1     %let a=b;
2     %let b=c;
3     %let c=a;
4     options symbolgen;
5     %let d=&c;
SYMBOLGEN:  Macro variable C resolves to a
6    %let e=&&c;
SYMBOLGEN:  && resolves to &.
SYMBOLGEN:  Macro variable C resolves to a
7    %let f=&&&c;
SYMBOLGEN:  && resolves to &.
SYMBOLGEN:  Macro variable C resolves to a
SYMBOLGEN:  Macro variable A resolves to b
8    %let g=&&&&c;
SYMBOLGEN:  && resolves to &.
SYMBOLGEN:  && resolves to &.
SYMBOLGEN:  && resolves to &.
SYMBOLGEN:  Macro variable C resolves to a
9    %let h=&&&&&c;
SYMBOLGEN:  && resolves to &.
SYMBOLGEN:  && resolves to &.
SYMBOLGEN:  Macro variable C resolves to a
SYMBOLGEN:  && resolves to &.
SYMBOLGEN:  Macro variable A resolves to b
10   %let i=&&&&&&c;
SYMBOLGEN:  && resolves to &.
SYMBOLGEN:  && resolves to &.
SYMBOLGEN:  && resolves to &.
SYMBOLGEN:  && resolves to &.
SYMBOLGEN:  Macro variable C resolves to a
SYMBOLGEN:  Macro variable A resolves to b
11   options nosymbolgen;
ballardw
Super User

You might be better off using %PUT statements to determine the evaluation of your data. The data step you use will set the length of the variable CHECK to the length of the first variable. Which could result in truncation. Please see:

 

%let a=b;
%let b= somethinglonger;

data test;
check="&a.";output;
check="&b.";output;
run;
proc print data=test;
run;

compare with:

%put A is: &a.;
%put B is: &b.;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 2200 views
  • 2 likes
  • 5 in conversation