0

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!

Joe
  • 62,789
  • 6
  • 49
  • 67
GabyLP
  • 3,649
  • 7
  • 45
  • 66

2 Answers2

1

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.

Joe
  • 62,789
  • 6
  • 49
  • 67
0

ok, this is not the best way to do it, but the solution would be to use the cats:

%let li=%sysfunc(cats(%,&numero));

and in the macro:

and name like "&li";

Do you know any other way to solve this????? is this the formal way to solve it? thanks

GabyLP
  • 3,649
  • 7
  • 45
  • 66
  • You could use `name like cats("%","&numero")` directly in the sql statement instead of creating a new macro variable. – Pekka Sep 07 '14 at 14:37
  • I don't know but I don't see any way it can get much simpler than that :) – Pekka Sep 07 '14 at 14:45