BookmarkSubscribeRSS Feed
kalbo
Obsidian | Level 7

hi, im trying to create a macro variable containing a search term such as %UNS%.

 

I will need to use this search term many times throughout the program.

 

For example:

%let searchterm=%UNS%;

 

data out;

set in (where=(visit like "&searchterm")) ;

run;

 

The problem is that the % is messing things up. How can I use such a macro variable?

 

 

5 REPLIES 5
PaigeMiller
Diamond | Level 26

%let searchterm=%nrstr(%%)UNS%nrstr(%%);

--
Paige Miller
Ksharp
Super User

%let searchterm=%nrstr(  %F%  );



data out;
set sashelp.heart (where=(sex like "&searchterm")) ;
run;

maguiremq
SAS Super FREQ

Use %NRBQUOTE.

data have;
input visit $;
datalines;
%UNS%
%NO%
%HI%
;
run;

%let searchterm = %nrbquote(%UNS%);

%put &searchterm.;

data want;
set have (where = (visit like "&searchterm"));
run;
Obs visit 
1 %UNS% 

https://v8doc.sas.com/sashtml/macro/z4bquote.htm  

Tom
Super User Tom
Super User

Why not just include the quotes in the macro variable?  The macro processor ignores strings bounded on the outside by single quotes.

%let searchterm='%UNS%';
data out;
  set in (where=(visit like &searchterm )) ;
run;

Or use a different search method.

%let searchterm=UNS;
data out;
  set in (where=(index(visit,"&searchterm")) ;
run;

 

Ksharp
Super User
Tom,
Good idea. But That is not readable for some user .

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 5 replies
  • 506 views
  • 1 like
  • 5 in conversation