Hello. I'm trying to run a macro with a wildcard in it. This the my macro code:
%macro oth(n,c,l);
data &c&n;
set &nopilot;
where othmedc&n like "%&c%" and med13&l.pn=1;
keep study_id othmedc&n med13&l.pn;
run;
%mend oth;
%oth(1,neuropathy,v)
Why do I get this error message:
WARNING: Apparent invocation of macro NEUROPATHY not resolved.
What is wrong with my code?
Thanks!
I think you need to quote the % before &c because when &c resolves to neuropathy, the resolved text looks like %neuropathy macro call. This % should not be considered a macro trigger rather should be considered as text by the macro processor. Therefore quoting the % is required and the following may help
where othmedc&n like %str("%%&c%%") and med13&l.pn=1;
Hi,
the error/warning is because condition
where othmedc&n like "%&c%" and med13&l.pn=1;
is resolved to:
where othmedc1like "%neuropathy%" and med13vpn=1;
and when SAS finds text >>%neuropathy<< text in double quotation marks (") so it tries to find macro named >>neuropathy<< and since can't it gives warning.
I think that simple workaround can be done in following way:
%macro oth(n,c,l);
data &c&n;
set &nopilot;
where othmedc&n like cats('%',"&c.",'%') and med13&l.pn=1;
keep study_id othmedc&n med13&l.pn;
run;
%mend oth;
All the best
Bart
Using %% will mask the second % from the macro processor so it won't get interpreted as a token for a macro that doesn't exist.
options mprint;
data have;
length study_id $1 othmedc1 $20 med13vpn 8;
call missing(of _all_);
med13vpn=1;
othmedc1='abcd Neuropathy xyz';
output;
othmedc1='abcd Xeuropathy xyz';
output;
stop;
run;
%let nopilot=have;
%macro oth(n,c,l);
data &c&n;
set &nopilot;
where upcase(othmedc&n) like %upcase("%%&c%%") and med13&l.pn=1;
keep study_id othmedc&n med13&l.pn;
run;
%mend oth;
%oth(1,neuropathy,v)
As a last resort, if nothing else works you can always build your string in a separate DATA step:
data _null_;
call symputx('string', "'%" || "&c" || "%'");
run;
Then use the macro variable for comparing:
where ..... like &string ......;
Don't add quotes around &STRING since the quotes are built into its value.
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.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.