Subscribe Bookmark RSS Feed

Renaming Columns in a script

whom

Community Trekker

Joined:

Jun 23, 2011

Ok, I guess I don't understand the JMP documentation. Short on good examples.

I'm trying to rename the columns in a JMP file that had columns names created with a prefix. All the column name start with "pre" and I want to strip that string from the column name.

In a loop, I was able to get all the column names extracted and displayed with a SHOW statement. I used

OldName = (Column name(i));

where i is the looping variable.

It seems like all I need to do is something like
substr(OldName,4,Length(OldName)-3)

but when I use that, I get all sorts of errors. Length function doesn't work for example.

WHAT am I doing wrong? The logic is so simple, but the JMP scripting language is killing me.
5 REPLIES
thechadd

Community Trekker

Joined:

Jun 23, 2011

I don't know *why* it works, but if you replace OldName with expr(OldName), it works for me:
dt = current data table ();
i = 1;
OldName = (Column name(i));
newvar = Substr( expr(OldName), 4, Length(expr( OldName )) - 3 );
show(newvar);
whom

Community Trekker

Joined:

Jun 23, 2011

That worked! Thanks!
ms

Super User

Joined:

Jun 23, 2011

Alternatively you can use

OldName = Char(Column name(i));

Then you do not need the Expr() within Substr().

The reason for not working without Char() (or expr) is that Column name() returns a name value, not a quoted string. See more in the scripting guide (under "obtaining column names" p. 121, JMP 9)

Message was edited by: MS
ms

Super User

Joined:

Jun 23, 2011

Or this single line solution:
mpb

Super User

Joined:

Jun 23, 2011

Or this which uses both set and get name: