Hello, I am learning macro quoting functions and I got some questions. Hope some of you expert can help 🙂
Below is the code I ran:
options mlogic mprint;
%macro translate (var);
%if &var = %str(EQ) %then %put The result is correct;
%else %put The result is incorrect;
%mend;
%translate(EQ)
The mlogic shows the condition is false :
%macro translate (var);
%if %bquote(&var) = %str(EQ) %then %put The result is correct;
%else %put The result is incorrect;
%mend;
%translate(EQ)
%macro translate (var);
%if %str(&var) = %str(EQ) %then %put The result is correct;
%else %put The result is incorrect;
%mend;
%translate(EQ)
options mlogic mprint;
%macro translate (var);
%if %bquote(&var) = %str(EQ) %then %put The result is correct;
%else %put The result is incorrect;
%mend;
%translate(EQ)
%str mask value in complie stage, %bquote mask value in execute stage.
compile stage is BEFORE execute stage.
Therefore BOTH worked.
Thanks for your response KSharp. I'm not sure if I followed tho. I thought the %str masks the value before it is resolved and it won't mask the resolved value. That's why we needed the bquote.
Below is an example that I read from another Sesug article:
%Let A = X,X ;
%Let B = Y%Str(&A)Y ;
%Put %Substr( %str(&B) , 4 , 1 );
In the third line, I'm masking &B with the %str function and it gives me error message:
%Let A = X,X ;
%Let B = Y%Str(&A)Y ;
%Put %Substr( %bquote(&B) , 4 , 1 );
Thanks so much! I know this topic is complex and this paper explains the concept very well. Will probably have to re-read it a few times to fully understand macro quoting.
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.
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.