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
Box75
Level I

FOR () Loop Script not working

I want to write a sequencing value to a new column after checking a condition (Time value) or a fixed set of rows.

Belo JMP script my script below creates a null value column.

Names Default To Here(1);
ROW = N ROW();
Run= New Column("Run", "numeric","ordinal");
n=1;
For(i = 1,
i<=ROW, i++,
If(:Time<1,i,i+1)
)

 

Any guidance from the community will be greatly appreciated.

 

 

3 REPLIES 3
Highlighted
txnelson
Super User

Re: FOR () Loop Script not working

Here is a simple script, that creates a :Time column, and then generates what I believe you are specifying should be your :Run column.  I generate the :Run column using 3 different methods.  You can read about all of  this in the Scripting Guide

     Help==>JMP Documentation Library...……….Scripting Guide

Names Default To Here( 1 );
dt = New Table( "Example",
	add rows( 20 ),
	New Column( "Time", formula( Random Uniform( .5, 1.5 ) ) )
);

dt << New Column( "Run1",
	"numeric",
	"ordinal",
	formula( If( :Time < 1, Row(), Row() + 1 ) )
);
	
dt << New Column( "Run2", numeric, ordinal );

For( i = 1, i <= N Rows( dt ), i++,
	If( :Time[i] < 1,
		:Run2[i] = i,
		:Run2[i] = i + 1
	)
);

dt << New Column( "Run3", numeric, ordinal );

For Each Row(
	If( :Time < 1,
		:Run3 = Row(),
		:Run3 = Row() + 1
	)
);
Jim
Highlighted
Box75
Level I

Re: FOR () Loop Script not working

@txnelson 

Thank You for your prompt guidance. Script partially worked. My time is in sequence and logic is assigning a new number to every row.

To make it simple, how do I create a column that counts rows up to 1 sec or 10 rows and assigns a number and repeats the process until the end of the table. 

 

Thank You for your help!

 

Highlighted
txnelson
Super User

Re: FOR () Loop Script not working

I believe the example below does what you want

Names Default To Here( 1 );
dt = New Table( "Example",
	add rows( 50 ),
	New Column( "Time",
		formula( Today() + Random Uniform( 10, 20. ) ),
		Format( "h:m:s", 11, 2 )
	)
);
dt << run formulas;
dt:time << delete formula;

dt << sort( by( :time ), order( ascending ), replace table( 1 ) );

dt << New Column( "Sequence",
	formula(
		If( Row() == 1,
			start = :time;
			count = 0;
		);
	
		If( count >= 10 | :Time - Start > 1,
			start = :time;
			count = 0;
		);
		count = count + 1;
	)
);
Jim
Article Labels