BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
pkm_edu
Quartz | Level 8
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?

1 ACCEPTED SOLUTION
7 REPLIES 7
pkm_edu
Quartz | Level 8

Thanks for the solution.

Alternatively, why does the following not work?

where upcase(memname) like %NRSTR("%_&ch");

pkm_edu
Quartz | Level 8

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?

Kurt_Bremser
Super User

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;
pkm_edu
Quartz | Level 8

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.

pkm_edu
Quartz | Level 8

Thanks for the detailed info.

sas-innovate-wordmark-2025-midnight.png

Register Today!

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.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1482 views
  • 2 likes
  • 3 in conversation