The following code provides me the desired results but the SAS Log shows the
following warnings.
WARNING: Apparent invocation of macro _T not resolved.
WARNING: Apparent invocation of macro _N not resolved.
data sashelp_data; set sashelp.vtable (where = (libname="SASHELP")) ; keep memname; run; %macro mymacro (df=, ch=); data &df; set sashelp_data; where upcase(memname) like "%_&ch"; run; %mend mymacro; %mymacro(df=er,ch=T) %mymacro(df=ip,ch=N)
Code explanation of "%_&ch" in the like condition: The wild character % is used as a substitute for zero or more characters while the '_' is used as a single character. &ch is a macro variable reference whose values are T and N in two macro calls.
Question: What would I do to avoid the above warnings?
I would appreciate it if someone could help me with a resolution of the issue?
Use single quotes around the LIKE string; this will prevent the macro processor from trying to resolve the % trigger.
Use single quotes around the LIKE string; this will prevent the macro processor from trying to resolve the % trigger.
Thanks for the solution.
Alternatively, why does the following not work?
where upcase(memname) like %NRSTR("%_&ch");
Although the single quotes around the LIKE string prevents the warning, the code does not produce the desired results.
NOTE: The data set WORK.ER has 0 observations and 1 variables.
Desired SAS Log:
NOTE: The data set WORK.ER has 21 observations and 1 variables.
NOTE: There were 12 observations read from the data set WORK.SASHELP_DATA
data sashelp_data; set sashelp.vtable (where = (libname="SASHELP")) ; keep memname; run; %macro mymacro (df=, ch=); data &df; set sashelp_data; where upcase(memname) like '%_&ch'; run; %mend mymacro; %mymacro(df=er,ch=T) %mymacro(df=ip,ch=N)
What am I doing wrong here?
You can use a concatenation to build the pattern string:
%macro mymacro (df=, ch=);
data &df;
set sashelp.vtable;
where libname = "SASHELP" and upcase(memname) like '%'!!"_&ch";
run;
%mend mymacro;
The code has worked. Concatenating the wild character (%) in single quotes with any single character (_) and the macro variable reference (_&ch) in double quotes makes sense to me. Thanks.
Thanks for the detailed info.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for 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.