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,_)||"'"

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—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
  • 21 replies
  • 4177 views
  • 1 like
  • 5 in conversation