cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
The Discovery Summit 2025 Call for Content is open! Submit an abstract today to present at our premier analytics conference.
Get the free JMP Student Edition for qualified students and instructors at degree granting institutions.
Choose Language Hide Translation Bar
View Original Published Thread

Add prefix to column names (scripting)

Newbie2Jumpie
Level IV

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

 

1 ACCEPTED SOLUTION

Accepted Solutions


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 );
);

 

View solution in original post

2 REPLIES 2


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 );
);

 

Newbie2Jumpie
Level IV


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 ); );