cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
lwx228
Level VIII

How to use function to find the first position greater than the specified starting position?

Use the function to find the first position of the weight column in the top 5 rows greater than 120.

Excuse me, Thanks!

 

2019-03-09_15-53-29.png

2 ACCEPTED SOLUTIONS

Accepted Solutions
txnelson
Super User

Re: How to use function to find the first position greater than the specified starting position?

Here is one way to do it

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/big class.jmp" );

dt << New Column( "match",
	formula(
		value = .;
		If( Row() > 5,
			count = 0;
			For( i = Row() - 5, i <= Row() - 1, i++,
				count++;
				If( :weight[i] > 120,
					value = count;
					Break();
				);
			);
		);
		value;
	)
);


 

 

Jim

View solution in original post

ms
Super User (Alumni) ms
Super User (Alumni)

Re: How to use function to find the first position greater than the specified starting position?

The JSL function that here corresponds to Excel's Match() would be Loc(). However, Loc() returns a matrix with the position of all matches, not just the first (or last).

 

Example:

dt << New Column("match",
    formula(If(Row() > 4, Loc(:weight[Row() - 4 :: Row()] > 120)[1]))
);

 

 

View solution in original post

3 REPLIES 3
txnelson
Super User

Re: How to use function to find the first position greater than the specified starting position?

Here is one way to do it

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/big class.jmp" );

dt << New Column( "match",
	formula(
		value = .;
		If( Row() > 5,
			count = 0;
			For( i = Row() - 5, i <= Row() - 1, i++,
				count++;
				If( :weight[i] > 120,
					value = count;
					Break();
				);
			);
		);
		value;
	)
);


 

 

Jim
lwx228
Level VIII

Re: How to use function to find the first position greater than the specified starting position?

It seems to me that this kind of calculation is needed by fewer people.

Thank Jim!
This calculation can be done in excel using a simple array formula.
{=MATCH(,IF(E2:E6>120,),)}
ms
Super User (Alumni) ms
Super User (Alumni)

Re: How to use function to find the first position greater than the specified starting position?

The JSL function that here corresponds to Excel's Match() would be Loc(). However, Loc() returns a matrix with the position of all matches, not just the first (or last).

 

Example:

dt << New Column("match",
    formula(If(Row() > 4, Loc(:weight[Row() - 4 :: Row()] > 120)[1]))
);