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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.