/***************************************************************************************************************** SAS file name: macro_quoting.sas File location: __________________________________________________________________________________________________________________ Purpose: To demonstrate 6 macro quoting functions, that solves most quoting problems: The Str, Nrstr, Bquote, Nrbquote and Superq. Author: Peter Clemmensen Creation Date: 13/04/2020 This program supports the blog post "6 SAS Macro Quoting Functions You Should Know" on SASnrd.com *****************************************************************************************************************/ /* Str and Nrstr Function - Masks at compilation */ /* No quoting */ %let ds = sashelp.class; %let st = proc print data=&ds; run;; %put &st; /* Str Function */ %let ds = sashelp.class; %let st = %str(proc print data=&ds; run;); %put &st; /* Nrstr Function */ %let ds = sashelp.class; %let st = %nrstr(proc print data=&ds; run;); %put &st; /* Bquote and Nrbquote - Masks at execution ie. after macro processor */ /* Bquote Function */ data _null_; v = "The dog's tail"; call symputx('a',v); run; %let b = %bquote(&a); %put &b; /* Nrbquote Function */ %let a = AT&T; %put The value of a is &a; %let a = %nrbquote(AT&T); %put The value of a is &a; /* Timing */ %let a = %left( one, two); /* Str masking */ %let a = %left(%str( one, two)); %put &a.; /* bquote masking */ %let a = one, two; %let b = %left(%bquote( &a)); %put &b.; /* Superq Function */ %macro DoIt; %put Macro DoIt Was Called!; %mend; data _null_; call symputx('a', 'Macro Var &SomeVar and Macro Call %DoIt'); run; %put &a; %put %superq(a);