I need to add a prefix to all variables in several data sets, with each data set using a different prefix. I have followed examples for doing this one data set at a time. The code below works exactly as intended. data have;
set sashelp.demographics;
run;
proc sql noprint;
select catx('=',name,catt('test_',name))
into :rename_list
separated by ' '
from sashelp.vcolumn
where libname = 'WORK' and memname = 'HAVE';
quit;
proc datasets library= work nolist;
modify have;
rename &rename_list;
quit;
proc contents data=have; run; I am looking to generalize this code with a macro, but the rename_list2 isnt being populated (see the put statement), and I'm not sure why. I have given the log output below the code. %macro name_prefix(library, dataset, prefix);
proc sql noprint;
select catx('=',name,catt(&prefix,name))
into :rename_list2
separated by ' '
from sashelp.vcolumn
where libname = '&library' and memname = '&dataset';
quit;
%put &rename_list2;
proc datasets library= &library nolist;
modify &dataset;
rename &rename_list2;
quit;
%mend name_prefix;
data have2;
set sashelp.demographics;
run;
%name_prefix(WORK,HAVE2,'test'); LOG MESSAGE
rename_list2
WARNING: Apparent symbolic reference RENAME_LIST2 not resolved.
NOTE: Line generated by the invoked macro "NAME_PREFIX".
26 rename &rename_list2; quit;
_
22
76
NOTE: Enter RUN; to continue or QUIT; to end the procedure.
ERROR 22-322: Expecting a name.
ERROR 76-322: Syntax error, statement will be ignored.
... View more