%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![]()
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.