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.