- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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
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
5 REPLIES 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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);
dt = current data table ();
i = 1;
OldName = (Column name(i));
newvar = Substr( expr(OldName), 4, Length(expr( OldName )) - 3 );
show(newvar);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Renaming Columns in a script
That worked! Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Renaming Columns in a script
Or this single line solution:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Renaming Columns in a script
Or this which uses both set and get name: