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
HarriBradbeer
Level II

How to add new column to all data tables

I have a series of experiments which produce a text file of results, titled with the name of the sample.

I have a script that takes the data table title and populates a new "sample name" column with the title.

dt = current data table();
name = dt << get name;
new column("Sample Name");
column(dt,"Sample Name")[1]=name;
nr = N Rows( dt ); For( ii = 2, ii <= nr, ii++, If( is missing(Column( dt, "Sample Name" )[ii]), Column(dt, "Sample Name" )[ii] = Column( dt, "Sample Name" )[ii - 1] ); );

The experiments are carried out dozens, even hundreds at a time. Is there an adaptation to my script I can put in to make this run on all open data tables so that I can concatenate all the results and continue to automate the analysis?

4 REPLIES 4
jthi
Super User

Re: How to add new column to all data tables

Do you want to add new column to each of the tables named "Sample Name" and it will contain only the name of that specific data table?

Names Default To Here(1);

Open("$SAMPLE_DATA/Big Class.jmp"); // open for demo purposes
Open("$SAMPLE_DATA/Big Class Families.jmp"); // open extra table for demo purposes

new_col_name = "Sample Name";

For Each({dt_cur}, Get Data Table List(),
	name = dt_cur << get name;
	If(!Contains(dt_cur << Get Column Names("String"), new_col_name),
		dt_cur << New Column(new_col_name, Character, Nominal, << Set Each Value(name));
	);
);

jthi_1-1657205506278.png

 

 

 

-Jarmo
HarriBradbeer
Level II

Re: How to add new column to all data tables

Thanks for your response.

I get an error when running this script

HarriBradbeer_0-1657207596311.png

 

jthi
Super User

Re: How to add new column to all data tables

You are most likely using older version of JMP (For Each was introduced in JMP16). Simple fix is to replace it with For loop (also fixed one typo on the code):

Names Default To Here(1);

Open("$SAMPLE_DATA/Big Class.jmp"); // open for demo purposes
Open("$SAMPLE_DATA/Big Class Families.jmp"); // open extra table for demo purposes

new_col_name = "Sample Name";

dt_list = Get Data Table List();
For(i = 1, i <= N Items(dt_list), i++,
	dt_cur = dt_list[i];
	name = dt_cur << get name;
	If(!Contains(dt_cur << Get Column Names("String"), new_col_name),
		dt_cur << New Column(new_col_name, Character, Nominal, << Set Each Value(name));
	);
);
-Jarmo
Georg
Level VII

Re: How to add new column to all data tables

If you need each table name only for concatenation, why not let concatenate doing the job, it has an option for this purpose? See Scripting index or help.

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Trial1.jmp" );
dt2 = Open( "$SAMPLE_DATA/Trial2.jmp" );
dt << Concatenate(
	Output Table( "Result Table with Source" ),
	Data Table( "Trial2" ),
	Create Source Column
);
Georg