Subscribe Bookmark RSS Feed

Re: Renaming columns with loop

masum111bd

Occasional Contributor

Joined:

Nov 11, 2017

Hi,

I am trying to rename few columns. Basically I want to append "OFL" character at the end of original column name.

I trried this script but no success.

dt = Current Data Table();
For( i = 25, i <= N Cols( dt ), i++,
newname = :Column Name( dt, i )||"OFL";
Column( dt, i ) << Set Name( newname );
);
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
David_Burnham

Super User

Joined:

Jul 13, 2011

Solution
dt = Current Data Table();
For( i = 25, i <= N Cols( dt ), i++,
	cName = Column(dt,i) << Get Name;
	newname = cName|| "OFL";
	Column( dt, i ) << Set Name( newname );
);
-Dave
3 REPLIES
Highlighted
David_Burnham

Super User

Joined:

Jul 13, 2011

Solution
dt = Current Data Table();
For( i = 25, i <= N Cols( dt ), i++,
	cName = Column(dt,i) << Get Name;
	newname = cName|| "OFL";
	Column( dt, i ) << Set Name( newname );
);
-Dave
masum111bd

Occasional Contributor

Joined:

Nov 11, 2017

Thanks David. It works fine.

markschahl

Community Trekker

Joined:

Jun 18, 2012

Just in case you want to do this with a second data table, here's how:

 

How-to-rename-columns-using-a-second-data-table

 

I use this a lot now since #TXNelson showed me how to do this!