It’s World Statistics Day! To honor the theme of the day, the JMP User Community is having conversations about the importance of trust in statistics and data. And we want to hear from you! Tell us the steps you take to ensure that your data is trustworthy.
Choose Language Hide Translation Bar
Highlighted
whom
Level I

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
Highlighted
ms
Super User ms
Super User

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
Highlighted
thechadd
Level IV

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);
Highlighted
whom
Level I

Re: Renaming Columns in a script

That worked! Thanks!
Highlighted
ms
Super User ms
Super User

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

Highlighted
ms
Super User ms
Super User

Re: Renaming Columns in a script

Or this single line solution:
Highlighted
mpb
Super User mpb
Super User

Re: Renaming Columns in a script

Or this which uses both set and get name:
Article Labels

    There are no labels assigned to this post.