AdministratorFebruary 6, 2021 at 11:33 pm
Q: ” I am wondering who knows how to remove all the underscore in the variable name? I have a data set with more than 200 variables and most of them have more than one underscores. Is there any way to automatically rename all the variables (removing the underscores in all of the variables in the data set) instead of rename them one by one? “
Under this circumstance, we need to use SAS macro for fulfill it. Below is my code.
options mprint source2 symbolgen;
input A_name $ B_sex $ C_age D_school $;
Jack M 19 Philip
Sara F 27 Thomas
create table Var as
where upcase(libname)='WORK' and upcase(memname)='C';
proc contents data=C out=Var_2(keep=name);
length combine $1000 combine_2 $1000;
combine_2=strip(name)||' as '||compress(name,'_');
select combine into: ALL separated by ' '
select combine_2 into: ALL_2 separated by ', '
set C( rename=(&ALL));
create table Z_2 as
Actually, to improve the processing efficiency, it is a much better way to use Proc Dataset than SQL or DATA step to do it. Do you know why?
Log in to reply.