%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
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.