DATA Step, Macro, Functions and more

macro quote question

Reply
Frequent Contributor
Posts: 77

macro quote question

SAS is not able to process the following macro code. Please help!

%let a=%str(store_name like "%MACY'S%" );

%put &a.;
Respected Advisor
Posts: 3,777

Re: macro quote question

This works I think. It can probably be simplified.

[pre]
%let a=%nrstr(store_name like "%%MACY%'S%%" );
%put &a.;

data test;
input store_name $10.;
cards;
MACY'S
DILLARD'S
;;;;
run;

proc sql;
select * from test where &a;
quit;
run;
[/pre]
Frequent Contributor
Posts: 77

Re: macro quote question

thanks _null_!

Your suggestion works.

Do you know how to correct the unbalanced quote problem created by my original macro code? My SAS completely stopped even though I applied the following code:

*';*";*%;
run;
SAS Employee
Posts: 104

Re: macro quote question

To correct the code:

1. Use %NRSTR instead of %STR to mask the actual % characters in your text. %STR does not mask % or & characters.

2. Use an extra % (as an escape character) before literal % characters and also before an unbalanced quote:

%let a=%nrstr(store_name like "%%MACY%'S%%" );

Finally, after submitting bad code (especially unbalanced quotes), an interactive SAS system may become unresponsive. To purge the system and restore functionality, first try submitting this code repeatedly:
*';*";*);%mend; run cancel;

You should eventually see this error message in the SAS log:
ERROR: No matching %MACRO statement for this %MEND statement.

This is the expected response to the %MEND statement in the above text string, and indicates that SAS has resumed normal operation. If this doesn't work, you'll probably need to restart SAS.
Regular Contributor
Posts: 241

Re: macro quote question

Either one below works as well.



   where store like '%MACY''S%'

 

   where index(store, "MACY'S")
Ask a Question
Discussion stats
  • 4 replies
  • 369 views
  • 0 likes
  • 4 in conversation