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!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.