BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
qw213
Calcite | Level 5

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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!


 

View solution in original post

2 REPLIES 2
Reeza
Super User

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!


 

qw213
Calcite | Level 5

Yes this is exactly what I am looking for. Thank you!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 2780 views
  • 0 likes
  • 2 in conversation