cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
whom
Level II

How to remove a prefix from multiple column names using JSL?

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.

1 ACCEPTED SOLUTION

Accepted Solutions
ms
Super User (Alumni) ms
Super User (Alumni)

Re: Renaming Columns in a script

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

View solution in original post

5 REPLIES 5

Re: Renaming Columns in a script

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
Level II

Re: Renaming Columns in a script

That worked! Thanks!
ms
Super User (Alumni) ms
Super User (Alumni)

Re: Renaming Columns in a script

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 (Alumni) ms
Super User (Alumni)

Re: Renaming Columns in a script

Or this single line solution:
mpb
mpb
Level VII

Re: Renaming Columns in a script

Or this which uses both set and get name: