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

Hello team,

What does && do in a sas macro?

Thanks,

Blue Blue

Blue Blue
1 ACCEPTED SOLUTION

Accepted Solutions
asuman
Obsidian | Level 7
I did not get your question clearly but this might help you:

%let x=temp;
%let n=3;
%let x3=result;
%let temp3 = result2;

%put &x&n;
%put &&x&n;
%put &&&x&n;


The scanner reads from left to right.
&x&n : Macro variable X resolves first to temp and then N resolves to 3. Output : temp3

&&x&n : Two ampersands (&&) resolves to one ampersand (&) and scanner continues and then N resolves to 3 and then &x3 resolves to result. Output : result

&&&x&n : First two ampersands (&&) resolves to & and then X resolves to temp and then N resolves to 3. In last, &temp3 resolves to result2. Output : result2

View solution in original post

4 REPLIES 4
ballardw
Super User

I am going to guess that you want to read the documentation for

Referencing Macro Variables Indirectly

 

not a three line subject.

 

Warning: this topic is a pathway to madness (i.e. code that is next to impossible to follow) if overused.

If you decide to experiment then

1) save your code before every execution

2) be prepared to create an unstable SAS session (depends on lots of factors)

3) be prepared for lots of "what the @#$%@# just happened"

asuman
Obsidian | Level 7
I did not get your question clearly but this might help you:

%let x=temp;
%let n=3;
%let x3=result;
%let temp3 = result2;

%put &x&n;
%put &&x&n;
%put &&&x&n;


The scanner reads from left to right.
&x&n : Macro variable X resolves first to temp and then N resolves to 3. Output : temp3

&&x&n : Two ampersands (&&) resolves to one ampersand (&) and scanner continues and then N resolves to 3 and then &x3 resolves to result. Output : result

&&&x&n : First two ampersands (&&) resolves to & and then X resolves to temp and then N resolves to 3. In last, &temp3 resolves to result2. Output : result2
Cynthia_sas
SAS Super FREQ
Hi:
My paper https://support.sas.com/resources/papers/proceedings13/120-2013.pdf (page 10-11 Figure 18) has an example of indirect reference and we cover the topic in our Macro Language 1 class.

Cynthia

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 16524 views
  • 9 likes
  • 5 in conversation