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!

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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