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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 7 replies
  • 1180 views
  • 2 likes
  • 3 in conversation