BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ifendo
Obsidian | Level 7

 




%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;

log.png 

 

I was about to check some macros, but happened to find this error while testing, where is the problem?

 

Thank you very much

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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)

View solution in original post

8 REPLIES 8
Reeza
Super User

What happens if you add a semicolon after &long?

ifendo
Obsidian | Level 7

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 whySmiley Sad

kanivan51
Obsidian | Level 7

%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;

Astounding
PROC Star

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)

ifendo
Obsidian | Level 7
Thank you very much for the explanation
Ksharp
Super User

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;
Tom
Super User Tom
Super User

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;
ifendo
Obsidian | Level 7

Thank you allSmiley Wink

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 2558 views
  • 4 likes
  • 6 in conversation