BookmarkSubscribeRSS Feed
MarcTC
Obsidian | Level 7
SAS is not able to process the following macro code. Please help!

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

%put &a.;
4 REPLIES 4
data_null__
Jade | Level 19
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]
MarcTC
Obsidian | Level 7
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;
SASJedi
Ammonite | Level 13
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.
Check out my Jedi SAS Tricks for SAS Users
chang_y_chung_hotmail_com
Obsidian | Level 7
Either one below works as well.



   where store like '%MACY''S%'

 

   where index(store, "MACY'S")

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 2112 views
  • 0 likes
  • 4 in conversation