Share your ideas for the JMP Scripting Unsession at Discovery Summit by September 17th. We hope to see you there!
Choose Language Hide Translation Bar
Highlighted
toddsmith77
Level I

Creating a New Column with Initial Sequence Data

I frequently concatenate multiple data tables into a single table and then add two new columns with initialized data. New Column 1 is called "Device" and is a constant that I enter. New Column 2 is called "Index" and is sequential data from 1 to x, where x is the last row in the data table. 

 

I would like to script the creation of these two new columns in the concatenated table, ideally with a Pop Up window to ask for the Device number.

 

Can anyone help me generate the script?

 

Thanks in advance!

4 REPLIES 4
Highlighted
txnelson
Super User

Re: Creating a New Column with Initial Sequence Data

OK, this will get you started.  Your side of the bargain is that you need to read the Scripting Guide, so you can learn about all of the items in the script, and also learn about what kinds of things you can do to make the script exactly what you want.

Names Default To Here( 1 );
dt = Current Data Table();

nw = New Window( "Device Input",
	<<modal,
	Border Box( top( 10 ), bottom( 10 ), Left( 10 ), Right( 10 ),
		sides( 15 ),
		Lineup Box( N Col( 1 ),
			Spacer Box( size( 0, 10 ) ),
			Text Box( "Enter Device Name" ),
			dev = Text Edit Box( " ",
				<<set script( devText = dev << get text )
			)
		)
	)
);

If( nw["button"] == 1,
	dt << New Column( "Device",
		character,set each value( devText )
	);
	dt << New Column( "index", set each value( Row() ) );
);
Jim
Highlighted
Jeff_Perkinson
Community Manager Community Manager

Re: Creating a New Column with Initial Sequence Data

I agree with @txnelson on reading the Scripting Guide.

 

I'd also encourage you to get familiar with the Formula Editor. In particular, the Sequence() and Count() functions could help you here. 

-Jeff
Highlighted
toddsmith77
Level I

Re: Creating a New Column with Initial Sequence Data

Hi Jim,

I will try this. Thank you for your assistance. I will read through the Scripting Guide as I generate the script.

Highlighted

Re: Creating a New Column with Initial Sequence Data

the script above is exactly what you need. So nothing to add for this. 

However, you can learn  a lot from JMP directly.

1. In your data table, you can  e.g. right click on the last column and choose "New Formula Column"->"Row"->"Row".

--> You will get a new column with a sequence in it from 1 to the end of the data table. 

2. Now click on the red triangle in the top left panel of the data table (the scripts part of th edata table). Select Copy Table Script (without data)

3. Open a script window and paste the code in it. At the bottom of the script you will find the script to create this new column with the formula using the Row() statement. This is what txnelson basically has used. 

 

Scripting index and scripting guide are your friends for JSL tasks. and deepen the understanding. But keep in mind you can come far with the automatic creation of code from JMP. 

That said, you should with any scripting/programming language always make yourself familiar to good programming practice