BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SAS_inquisitive
Lapis Lazuli | Level 10

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
Loko
Barite | Level 11

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

3 REPLIES 3
Ksharp
Super User

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.

Tom
Super User Tom
Super User

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);
Loko
Barite | Level 11

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

 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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