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