%macro test1;
data a;
a=1;
put "a long text";
run;
%mend;
%test1; * this works;
%let long=%nrbquote(%test1);
%put &long;
options mprint mlogic symbolgen;
%macro test2;
%if &long ne %str( ) %then %do;
data b;
b=1;
%end;
&long /* problem here, why? */
proc print width=min;
run;
%mend;
%test2;
I was about to check some macros, but happened to find this error while testing, where is the problem?
Thank you very much
The contents of &long have been quoted by %NRBQUOTE. That includes the double quotes surrounding "a long text". Evidently, SAS isn't figuring out to unquote those in time to parse the statement correctly. Try replacing this:
&long
Instead, use:
%unquote(&long)
What happens if you add a semicolon after &long?
Thank you, Reeza. I still got the same error if i add a semicolon...
but if i remove the the put "a long text" , it works, do not know why
%macro test1;
%do;
data a;
a=1;
%put a long text; /*There must be a sign "%"*/
run;
%end;
%mend;
%test1;
%let long=%nrbquote(%test1);
%put &long;
options mprint mlogic symbolgen;
%macro test2;
%if &long ne %str( ) %then %do;
data b;
b=1;
run;
%end;
&long /* problem here, why? */
proc print width=min;
run;
%mend;
%test2;
The contents of &long have been quoted by %NRBQUOTE. That includes the double quotes surrounding "a long text". Evidently, SAS isn't figuring out to unquote those in time to parse the statement correctly. Try replacing this:
&long
Instead, use:
%unquote(&long)
Try %UNQUOTE()
%macro test1;
data a;
a=1;
put "a long text";
run;
%mend;
%test1
%let long=%nrbquote(%test1);
%put &long;
options mprint mlogic symbolgen;
%macro test2;
%if &long ne %then %do;
data b;
b=1;
run;
%end;
%unquote(&long)
proc print width=min;
run;
%mend;
%test2;
The macro quoting introduced by the %NRBQUOTE() function is causing the generated code to not be valid SAS syntax.
Use the %UNQUOTE() function to remove the macro quoting when you no longer need it.
Here is a simplier example.
%let mvar1=put "no macro quoting";
%let mvar2=%nrbquote(put "macro quoting");
data _null_;
&mvar1;
run;
data _null_;
&mvar2;
run;
data _null_;
%unquote(&mvar2);
run;
Thank you all
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.