BookmarkSubscribeRSS Feed
jmkroll
Calcite | Level 5
I have been pulling my hair out with this. I want to create a macro that submits some SQL code. The SQL code contains a WHERE clause using the LIKE operator. I need to include a macro variable in the LIKE string. Here is what it looks like.

%Macro MyMac(name);
Proc SQL;
Select *
From somefile
WHERE somefield LIKE "%&name%";
%Mend;

%MyMac(jeff);

The resulting SQL code should look like

Proc SQL
Select *
From somefile
WHERE somefield LIKE "%jeff%";

Those two percent signs are killing me. Can anyone come up with a series of macro functions that would result in the string Im looking for? Your help is appreciated.

Jeff
2 REPLIES 2
Olivier
Pyrite | Level 9
What you need is a QUOTING function. Quoting is the art of hiding characters, preventing the macro processor to do them wrong. In that case, %NRBQUOTE seems to work out fine.
[pre]
WHERE name LIKE "%NRBQUOTE(%)&name%NRBQUOTE(%)" ;
[/pre]
Regards.
Olivier
jmkroll
Calcite | Level 5
Thanks Olivier. I had a feeling it would be something as simple as that. It worked perfectly.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 671 views
  • 0 likes
  • 2 in conversation