DATA Step, Macro, Functions and more

macro quoting at macro parameter value

Accepted Solution Solved
Reply
Regular Contributor
Posts: 234
Accepted Solution

macro quoting at macro parameter value

Hello, 

 

The following program was taken from this paper where %NRBQUOTE (%NRQUOTE) is used to quote macro parameter value. (http://www.lexjansen.com/phuse/2014/cc/CC02.pdf)

 

%MACRO Ex_3(Food);
	%IF (&Food EQ %NRSTR(Rice & Beans)) %THEN
		%PUT Try the House Special - &Food;
	%ELSE %PUT &Food - a tasty snack!;
%MEND Ex_3;

%Ex_3(%NRBQUOTE(Rice & Beans));

When I use %NRSTR as macro quoting function for parameter value I get the same result. So in this situation both compile time and execution time macro quoting functions can be used?

 

%MACRO Ex_3(Food);
	%IF (&Food EQ %NRSTR(Rice & Beans)) %THEN
		%PUT Try the House Special - &Food;
	%ELSE %PUT &Food - a tasty snack!;
%MEND Ex_3;

%Ex_3(%NRSTR(Rice & Beans));

 


Accepted Solutions
Solution
‎10-26-2016 09:07 PM
Super Contributor
Posts: 305

Re: macro quoting at macro parameter value

Hello,

 

in your example there is no diiference in the result no matter you use %NRBQUOTE or %NRSTR.

 

But consider the following examples (where Rice&Beans are written without any space) and you may notice the difference between them.

%MACRO Ex_3(Food);
	%IF (&Food EQ %NRSTR(Rice&Beans)) %THEN
		%PUT Try the House Special - &Food;
	%ELSE %PUT &Food - a tasty snack!;
%MEND Ex_3;

/*macro variable &beans is not resolved therefore besides the put message
there is also an warning message in the log*/
%Ex_3(%NRBQUOTE(Rice&Beans));
/*macro variable &beans is maske therefore the put message written in the log*/
%Ex_3(%NRSTR(Rice&Beans));

 

 

View solution in original post


All Replies
Super User
Posts: 9,682

Re: macro quoting at macro parameter value

Yes. %NRBQUOTE is usually for macro variable. Since you don't have any macro variable in parameter ,

no macro variable would be explained in %NRBQUOTE . Both %NRBQUOTE and %NRSTR(is for text) would be accepted.

Super User
Super User
Posts: 6,502

Re: macro quoting at macro parameter value

You are quoting in the wrong place. You do not need to quote your example value in the macro call.  You need to quote the value in the implied %EVAL() function call that the %IF statement is generating.

 

%MACRO Ex_3(Food);
	%IF (%superq(food) EQ %NRSTR(Rice & Beans)) %THEN
		%PUT Try the House Special - &Food;
	%ELSE %PUT &Food - a tasty snack!;
%MEND Ex_3;

%Ex_3(Rice & Beans);
Solution
‎10-26-2016 09:07 PM
Super Contributor
Posts: 305

Re: macro quoting at macro parameter value

Hello,

 

in your example there is no diiference in the result no matter you use %NRBQUOTE or %NRSTR.

 

But consider the following examples (where Rice&Beans are written without any space) and you may notice the difference between them.

%MACRO Ex_3(Food);
	%IF (&Food EQ %NRSTR(Rice&Beans)) %THEN
		%PUT Try the House Special - &Food;
	%ELSE %PUT &Food - a tasty snack!;
%MEND Ex_3;

/*macro variable &beans is not resolved therefore besides the put message
there is also an warning message in the log*/
%Ex_3(%NRBQUOTE(Rice&Beans));
/*macro variable &beans is maske therefore the put message written in the log*/
%Ex_3(%NRSTR(Rice&Beans));

 

 

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 226 views
  • 3 likes
  • 4 in conversation