cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
Jackie_
Level VI

Adding numbers to columns

Hi,

@txnelson,

I am new to JSL Scripting.

Is there a way I could number all the columns using a jsl script? There are 100 columns in the data table and I want to concatenate number in the column names

 

 On example, there are multiples columns that follow this type:-

Jacksmith12_1-1629814123296.png

Looking for some feedback

Thanks,

Jay

1 ACCEPTED SOLUTION

Accepted Solutions
ih
Super User (Alumni) ih
Super User (Alumni)

Re: Adding numbers to columns

Hi @Jackie_ ,

 

You could use a short script to do this:

Names default to here(1);

dt = Open("$Sample_data/iris.jmp");

cols = dt << Get column names;

for(c = 1, c<= n items(cols), c++,
	Column(dt, c) << Set Name( char(c) || ". " || ( Column(dt, c) << Get Name ) )
);

View solution in original post

5 REPLIES 5
ih
Super User (Alumni) ih
Super User (Alumni)

Re: Adding numbers to columns

Hi @Jackie_ ,

 

You could use a short script to do this:

Names default to here(1);

dt = Open("$Sample_data/iris.jmp");

cols = dt << Get column names;

for(c = 1, c<= n items(cols), c++,
	Column(dt, c) << Set Name( char(c) || ". " || ( Column(dt, c) << Get Name ) )
);
Jackie_
Level VI

Re: Adding numbers to columns

Thanks, @ih 

 

I want to assign numbers only to a particular group of columns.

For eg: In this case, I want to serialize the column group "Tests". There are more than 100 columns in the tests groups. Please can you help me with the jsl? 

Jacksmith12_3-1629815445220.png

Many thanks,

Jack

ih
Super User (Alumni) ih
Super User (Alumni)

Re: Adding numbers to columns

If you are working interactively then the function get selected columns might help:

 

Names default to here(1);

dt = Open("$Sample_data/iris.jmp");

dt:Sepal length << Set Selected(1);
dt:Sepal width << Set Selected(1);

cols = dt << Get selected columns;

for(c = 1, c<= n items(cols), c++,
	Column(dt, c) << Set Name( char(c) || ". " || ( Column(dt, c) << Get Name ) )
);

Otherwise you could include an if statement in the for loop to ensure the name matches whatever criteria you have.

jthi
Super User

Re: Adding numbers to columns

If you are using JMP16 you could also try  with Transform Each (or For Each):

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");

Transform Each({value, idx}, dt << Get Column Names("String"),
	Column(dt, value) << Set Name(Char(idx) ||". " || value);
);
-Jarmo
txnelson
Super User

Re: Adding numbers to columns

  1. Please take the time to read the Scripting Guide in the JMP Documentation Library available under the Help pull down menu.
  2. All you need to do, is to loop across the columns and change the column name
    Names Default To Here( 1 );
    dt = Current Data Table();
    
    For( i = 1, i <= N Cols( dt ), i++,
    	Column( dt, i ) << set name( Char( i ) || ". " || Char( Column( dt, i ) << get name ) )
    );
Jim