cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
SING
Level II

Concat columns and adding to each loop

Hello,

If there have a data table like below, how can i using scripts to concat equipmentId and stage_num to new columns with each step?

Thanks.

 

SING_1-1689142700539.png

 

 

5 REPLIES 5
jthi
Super User

Re: Concat columns and adding to each loop

First loop over your data and create the pairs of interest (if they are always next to each other this might be a bit easier). Then loop over the pairs while creating new columns. If you could provide example of your data it would be easier to provide an example scripts.

-Jarmo
SING
Level II

Re: Concat columns and adding to each loop

Hi jthi,

Here's the data sample.

jthi
Super User

Re: Concat columns and adding to each loop

One example

Names Default To Here(1);

dt = Open("$DOWNLOADS/example data.jmp");
dt << Clear Select;
// as all columns are interest to use and they are always in pairs
// we can loop over every other column
col_list = dt << Get Column Names("String");
first_col_indices = 1::N Items(col_list)::2;

new_col_list = {};
For Each({first_col_idx}, first_col_indices,
	first_col_name = Column(dt, first_col_idx) << get name;
	new_col_name = Word(1, first_col_name, ":");
	Insert Into(new_col_list, dt << New Column(new_col_name, Character, Nominal, << Set Each Value(
		Column(dt, first_col_idx)[Row()] ||"_"||Column(dt, first_col_idx + 1)[Row()]
	)));
);

/*
For Each({new_col, idx}, new_col_list,
	dt << Move Selected Columns(new_col, After(Column(dt, first_col_indices[idx] + 1 + idx - 1)));
);
*/
-Jarmo
SING
Level II

Re: Concat columns and adding to each loop

Hi jthi,

 

It works on this data sample, but if my data have another columns which is not relate to the columns that i would like to concat, for example only photo and stage column need to concat, but  DRY ETCH column not, like the example data 2 at below, how could I fix your code? 

Many thanks!

 

 

jthi
Super User

Re: Concat columns and adding to each loop

Are the columns always pairs or is it possible that other part of pair is missing? And if it is possible, how should that situation be handled? Also, are columns always in "correct" order?

-Jarmo