I am trying to rename all the columns by adding a sequence as suffix. For example, right now my column names are A B C... and I want to rename them to var1 var2 var3...
Is there a way to do it? Thanks!
There are many ways. If you have a few it's likely easier to manually do it. If you have a large amount then a macro variable is nice. Here's an example:
Modify this to use your libname and data set name. Check to ensure the case matches.
proc sql noprint;
select catx("=", name, catt('VAR', put(varnum, 2. -l)))
into :rename_list
separated by " "
from sashelp.vcolumn
where libname='WORK'
and memname='SAMPLE';
quit;
%put &rename_list;
proc datasets library=work nodetails nolist;
modify sample;
rename &rename_list;
run; quit;
proc print data=sample noobs;
run;
@qw213 wrote:
I am trying to rename all the columns by adding a sequence as suffix. For example, right now my column names are A B C... and I want to rename them to var1 var2 var3...
Is there a way to do it? Thanks!
There are many ways. If you have a few it's likely easier to manually do it. If you have a large amount then a macro variable is nice. Here's an example:
Modify this to use your libname and data set name. Check to ensure the case matches.
proc sql noprint;
select catx("=", name, catt('VAR', put(varnum, 2. -l)))
into :rename_list
separated by " "
from sashelp.vcolumn
where libname='WORK'
and memname='SAMPLE';
quit;
%put &rename_list;
proc datasets library=work nodetails nolist;
modify sample;
rename &rename_list;
run; quit;
proc print data=sample noobs;
run;
@qw213 wrote:
I am trying to rename all the columns by adding a sequence as suffix. For example, right now my column names are A B C... and I want to rename them to var1 var2 var3...
Is there a way to do it? Thanks!
Yes this is exactly what I am looking for. Thank you!
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.