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
ReginaHong
Level III

JSL script if statement then Delete Column

Hi,

I am new to JSL script. How do I write in JSL script for the scenario below:

If  last 10 rows in column A <= to last 10 rows in column B, then delete column C and column E else delete column D and column F. The values in the last 10 rows within columns A & B are always the same. Can anyone help to translate this into JSL script?

 

Pic1.JPG

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
txnelson
Super User

Re: JSL script if statement then Delete Column

If I am interpreting your request properly, the following simple script will give you what you want

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

// Initialize a counter
count = 0;

// Loop through the last 10 rows and count
// the number of times :A<=:B
For( i = N Rows( dt ) - 9, i <= N Rows( dt ),
	i++,
	If( :A[i] <= :B[i], count++ )
);

// Handle the 2 scenarios for which columns to delete
If( count == 10,
	dt << delete columns( {"C", "E"} ),
	dt << delete columns( {"D", "F"} )
);
Jim

View solution in original post

1 REPLY 1
Highlighted
txnelson
Super User

Re: JSL script if statement then Delete Column

If I am interpreting your request properly, the following simple script will give you what you want

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

// Initialize a counter
count = 0;

// Loop through the last 10 rows and count
// the number of times :A<=:B
For( i = N Rows( dt ) - 9, i <= N Rows( dt ),
	i++,
	If( :A[i] <= :B[i], count++ )
);

// Handle the 2 scenarios for which columns to delete
If( count == 10,
	dt << delete columns( {"C", "E"} ),
	dt << delete columns( {"D", "F"} )
);
Jim

View solution in original post

Article Labels

    There are no labels assigned to this post.