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
SAS Super FREQ
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")

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
  • 4 replies
  • 1333 views
  • 0 likes
  • 4 in conversation