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?
%let searchterm=%nrstr(%%)UNS%nrstr(%%);
%let searchterm=%nrstr( %F% );
data out;
set sashelp.heart (where=(sex like "&searchterm")) ;
run;
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%
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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.