Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- Re: How to use function to find the first position greater than the specified s...

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Mar 9, 2019 12:12 AM
(5301 views)

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

Excuse me, Thanks!

2 ACCEPTED SOLUTIONS

Accepted Solutions

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Created:
Mar 9, 2019 4:41 AM
| Last Modified: Mar 9, 2019 4:46 AM
(5287 views)
| Posted in reply to message from lwx228 03-09-2019

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

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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]))
);
```

3 REPLIES 3

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Created:
Mar 9, 2019 4:41 AM
| Last Modified: Mar 9, 2019 4:46 AM
(5288 views)
| Posted in reply to message from lwx228 03-09-2019

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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,),)}

Thank Jim!

This calculation can be done in excel using a simple array formula.

{=MATCH(,IF(E2:E6>120,),)}

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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]))
);
```

Article Labels

There are no labels assigned to this post.