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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.