Macro sas difference between %str and %bquote

Rohit Gupta picture Rohit Gupta · Dec 24, 2014 · Viewed 9.8k times · Source

Sample Code :-

%Let a = begin;

%let b1 = %str(&a);

%let b2 = %nrstr(&a);

%let b3 = %bquote(&a);

%let b4 = %nrbquote(&a);

%let b = end;

Actual Output :-

b1 = begin 
b2 = &a 
b3 = begin 
b4 = begin

Expected Output :-

b3 = end     
b4 = &a

Is this because bquote and nrquote are execution time whereas str and nrstr are compile time ?

Answer

Kostya picture Kostya · Dec 24, 2014

As explained in SAS manual http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#z3514quote.htm,

%QUOTE and %NRQUOTE mask the same items as %STR and %NRSTR, respectively. However, %STR and %NRSTR mask constant text instead of a resolved value. And, %STR and %NRSTR work when a macro compiles, while %QUOTE and %NRQUOTE work when a macro executes.