DATA Step, Macro, Functions and more

Macro Quoting functions

Reply
Super Contributor
Posts: 426

Macro Quoting functions

May I request someone to provide me an easy example to understand the macro functions like %str, %nrstr, %quote and %bquote? Although I read the documentation I've trouble understanding them.

 

Thanks!

Super User
Posts: 5,260

Re: Macro Quoting functions

If there were an easy/short explanation for this, I'm pretty sure that should be in the documentation.

Read again, read various papers on the subject.

Use examples in doc, modify them and notice the behaviour.

Data never sleeps
Respected Advisor
Posts: 3,777

Re: Macro Quoting functions

I recall a really nice blog post from one of the SAS folks on this subject.  Does anyone remember that or am I having a senior moment?

PROC Star
Posts: 1,236

Re: Macro Quoting functions

Perhaps @data_null__ you are referring to this blog post from Russ Tyndall.  I think it's an excellent resource. 

http://blogs.sas.com/content/sgf/2014/08/15/macro-quoting-made-easy/

 

For more detailed reviews, see UG such as:

Whitlock: http://www.lexjansen.com/nesug/nesug03/at/at012.pdf

Dunn: http://www.lexjansen.com/scsug/2010/Dunn_5/Macro_Quoting.pdf

 

Trusted Advisor
Posts: 1,115

Re: Macro Quoting functions

A former colleague of mine, Roland Rashleigh-Berry, has published a nice article on this subject: http://www.datasavantconsulting.com/roland/mquoting.html

I think you'll like it.

Super User
Super User
Posts: 7,413

Re: Macro Quoting functions

Just my opinion, but if your having to use these, then there is 95% chance of a better way of doing things using Base SAS programming, in fact other than 1% of extreme circumstances, almost everything can be done in Base SAS.

Super User
Posts: 9,687

Re: Macro Quoting functions

 Quickly  go through this . Detials check documentation.

 

%str, %nrstr  ,%quote ,%bquote are all used to mask the special characters (like blank comma ..) in a string.

 

%str, %nrstr  are generally for a STRING .

%str will resolve the macro variable if it is included in the STRING. and need add % before non-pair  '  " (  )  %    

%nrstr will NOT resolve the macro variable if it is included in the STRING. and need add % before non-pair  '  " (  )  %    

 

 

%quote ,%bquote are generally for a MACRO VARIABLE .

%quote is old version of %bquote . Now almost be replaced by %bquote .

 %bquote  unlike %quote  which need add % before non-pair  '  "  

Super Contributor
Posts: 426

Re: Macro Quoting functions

Thank you!

 

An simple example would be helpful.

Super User
Posts: 9,687

Re: Macro Quoting functions

OK.

 

 

%str, %nrstr  are generally for a STRING .

%str will resolve the macro variable if it is included in the STRING. and need add % before non-pair  '  " (  )  %    

1)
54 %let a=xxx;
55 %let b=%str(xxx&a.xxx);
56 %put &b ;
xxxxxxxxx

 

2)

54 %let a=xxx;
55 %let b=%str(xxx&a.x%'xx%"xx%%);
56 %put &b ;
xxxxxxx'xx"xx%
 
 

%nrstr will NOT resolve the macro variable if it is included in the STRING. and need add % before non-pair  '  " (  )  %    

1)

54 %let a=xxx;

55 %let b=%nrstr(xxx&a.x%'xx%"xx%%);
56 %put &b ;
xxx&a.x'xx"xx%

 

 

 

%quote ,%bquote are generally for a MACRO VARIABLE .

%quote is old version of %bquote . Now almost be replaced by %bquote .

 %bquote  unlike %quote  which need add % before non-pair  '  "  

%bquote will resolve the macro variable in it .

1)

54 %let a=xxx;
55 %let b=%bquote(xxx&a.x'xx"xx);
56 %put &b ;
xxxxxxx'xx"xx
Ask a Question
Discussion stats
  • 8 replies
  • 336 views
  • 2 likes
  • 7 in conversation