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.;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 4 replies
  • 1627 views
  • 2 likes
  • 5 in conversation