I have large SAS dataset that has spaces in the variable name. I wish to replace the space with underscore. For Example Bus City = Bus_City. I found this macro in the formun that removes the spaces only. Using the above example, this macro does this: Bus City =BusCity Can someone please help me modify this macro to replace the space with underscore. data sample;
set sashelp.class;
age_student=age;
'gender - student'n=sex;
run;
%macro rename_vars(table, remove_char);
%let table=%upcase(&table);
%let rename_list=;
proc sql noprint;
select cats("'",name,"'n =",compress(name, "&remove_char")) into :rename_list
separated by " "
from sashelp.vcolumn
where upper(libname)="%scan(WORK.&table,-2)"
and upper(memname)="%scan(&table,-1)"
and findc(strip(name), "&remove_char")>0;
quit;
%put rename_list: %bquote(&rename_list);
%if %bquote(&rename_list) ne %then
%do;
proc datasets lib=%scan(WORK.&table,-2);
modify %scan(&table,-1);
rename &rename_list;
run;
quit;
%end;
%mend;
/* call the macro. First parameter is the table name,
second parameter the characters to be removed in variable names */
%rename_vars(sample,' ');
... View more