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

JSL Script

Hi All,

I am completely new to JMP and writing JSL scripts and I needed a help in building a logic for a case:

I have a table with one of the column as Status and I would like to count the number of 1's in that. It will start counting when it sees first "1" and continue to count until the last and output the final count at the last occurence of 1. And once it sees "0" in the next row, it should reset the counter again and start looking for "1".


I would be really grateful if you help me with this.


Super User

Re: JSL Script

Could do this


Names default to here(1);
m = [0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0];
dt = new table("Test", 
	<< New Column("Status", <<Set Values(m));


dt << New Column("Output", <<Formula(If( :Status,
	Lag( :Output, 1 ) + 1,
Vince Faller - Predictum
Level I

Re: JSL Script

Thank you for the help. The logic is very simple and straight forward and it helps a lot. Thanks again.
Super User

Re: JSL Script

names default to here(1);

// create the table
m = [0,0,0,0,0,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,0,0,0];
dt = new table("Test", 
	new column("Status", set values(m));

// create the empty status column
dt << new column("Output");

// iterate over each row of the table
result = 0;  // counter for consecutive 1's
for (i=1,i<=nrows(dt),i++,
	// apply the logic the way
	// that you would think it
	value = dt:Status[i];  // i'th row of Status column table referenced by dt
	if (value==0,
		dt:Output[i] = 0;  
		result = 0;
		result = result + 1;
		dt:Output[i] = result;
Article Labels

    There are no labels assigned to this post.