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

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2809 views
  • 0 likes
  • 2 in conversation