cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Sign-in to the JMP Community will be unavailable intermittently Dec. 6-7 due to a system update. Thank you for your understanding!
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.
  • JMP 19 is here! Learn more about the new features.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
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
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
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

Recommended Articles