There is no need add quotes around string literals in macro code. Everything is a string to macro code. Also if you want to use %INDEX() to test if a string begins with specific characters then you need to worry both about the case of the string and the position that the characters are found. So to find names that start with 'ID_' you could use:
%IF %index(%upcase(&&var&i),ID_) = 1 %THEN ....;
But in reality you can take the testing of the variable name out of macro logic and put it into regular SAS logic where it is easier to code and to debug.
Here is version of your macro that greatly simplies the metadata query to get the list of variables that begin with 'ID_'.
%macro rename(lib,dsn,prefix);
%local i nvar ;
proc sql noprint ;
select name into :var1-
from dictionary.columns
where libname=%upcase("&LIB")
and memname=%upcase("&DSN")
and upcase(name) like 'ID^_%' escape '^'
;
%let nvar=&sqlobs;
quit;
%if (&nvar) %then %do;
proc datasets lib=&lib nolist ;
modify &dsn ;
rename
%do i=1 %to &sqlobs ;
&&var&i = &prefix._&&var&i
%end;
;
run; quit;
%end;
%mend rename ;
... View more