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

If you want to use macro variable A then it must be prefixed with &
Your code is referring to data variable A
gyambqt
Obsidian | Level 7
Yeah I fixed the code now. But it still didn't work
Peter_C
Rhodochrosite | Level 12
The base SAS language provides two stages for processing
1 deriving syntax (called macro language processing)
2 processing data in the data step iteration (or running a procedure like FREQ)
There is no need to make the functionality of one of these "stages", do both jobs.
Peter_C
Rhodochrosite | Level 12
did you try

%let a = a_b;
data a;
a= "%scan(&a,2,_)" ;
run;
gyambqt
Obsidian | Level 7

Yeah but the % inside of double quotation won't get processed properly.

Kurt_Bremser
Super User

@gyambqt wrote:

Yeah but the % inside of double quotation won't get processed properly.


Nonsense. Double quotes are exactly what's needed to resolve macro triggers:

%let a=%str(a_b); /* is equivalent to %let a=a_b; */

data a;
a = "%scan(&a,2,_)";
run;

proc print data=a;
run;

Dataset a contains the value "b" in variable a.

gyambqt
Obsidian | Level 7

Hmm is a="%scan(&a,2_)" equivlent to a= "'"||%scan(&a,2,_)||"'"

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
  • 21 replies
  • 3851 views
  • 1 like
  • 5 in conversation