I need to use the following code inse a macro:
proc sql;
select name
into :lista
separated by ' '
from dictionary.columns
where libname='LABO2'
and name like 't1_%'
and name like "%5";
quit;
But when I write:
%macro prue(numero);
proc sql;
select name
into :listas
separated by ' '
from dictionary.columns
where libname='LABO2'
and name like 't1_%'
and name like "% &numero.";
quit;
%put "% &numero";
%mend;
%prue(5);
I get in the like '% 5' when I need '%5'. If I delete the blanck space in
like "%&numero."
I don't get the variable value 5, I get '%&numero'. So I don't know how to solve this.
Thanks!
You need to use macro quoting to escape the percent sign and/or to separate it from the macro variable. One solution of many:
%let text=fred;
proc sql;
select name from sashelp.class
where name like "%nrstr(%%)&text.";
quit;
You double the %
because the first % in a %str
or %nrstr
escapes certain characters, including percent itself.