- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Add prefix to column names (scripting)
Hi
I have a a JMP dataset and want to a add the same prefix to all the column names in that dataset, my code below doesn't do quite what I want.
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt2 = dt << For( i = 25, i <= N Cols( dt ), i++,
cName = Column( dt, i ) << Get Name;
newname = cName || "Prefix_";
Column( dt, i ) << Set Name( newname );
);
Now, a second scenario:
Imagine the column "sex" in "Big Class" contains Fs only (or Ms).
How could I the access that contant and use it as a prefix by the help of a utility/macro variable in the code above?
Cheers, Newbie
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Add prefix to column names (scripting)
First, For() is a function, not a message for a data table, that does not return a reference to a new data table. Second, why start the loop index at 25? Third, why concatenate a prefix after the name? That result is a suffix.
Names Default to Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
prefix = dt:sex[1];
For( i = 1, i <= N Cols( dt ), i++,
cName = Column( dt, i ) << Get Name;
newname = prefix || cName;
Column( dt, i ) << Set Name( newname );
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Add prefix to column names (scripting)
First, For() is a function, not a message for a data table, that does not return a reference to a new data table. Second, why start the loop index at 25? Third, why concatenate a prefix after the name? That result is a suffix.
Names Default to Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
prefix = dt:sex[1];
For( i = 1, i <= N Cols( dt ), i++,
cName = Column( dt, i ) << Get Name;
newname = prefix || cName;
Column( dt, i ) << Set Name( newname );
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Add prefix to column names (scripting)
I'm sorry, Mark. I didn't notice the buffer didn't contain=paste the most recent JSL code variant.
Anyway, I tweaked it a tiny bit...
Names Default to Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
prefix = dt:sex[1];
For( i = 1, i <= N Cols( dt ), i++,
cName = Column( dt, i ) << Get Name;
newname = prefix ||"_"||cName;
Column( dt, i ) << Set Name( newname ); );