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
- :
- Need help for using Lag function

Topic Options

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

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

Nov 6, 2017 12:49 AM
(1106 views)

Hello everyone!

Hope someone could help me with this:

What is is the expected output of the following code?

After evaluation I get the following Log:

And the new columns just looks like this:

SliderID column is :

Hope someone could enlighten me with this! thanks in advance! :)

2 ACCEPTED SOLUTIONS

Accepted Solutions

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

Nov 6, 2017 1:59 AM
(2044 views)

Solution

Your formula is missing an if statement. It should be something like

`Formula(If(:sliderID == lag(:sliderID,1),1,0))`

I would recommend you get all the steps working by using the menus and mouse clicks before trying to script it.

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

Nov 6, 2017 4:08 AM
(2037 views)

Solution

Your formula

```
:SliderID == Lag(:SiiderID, 1 )
```

is a boolean operation. When the current rows value of SliderID is equal to the previous row's value os SliderID, "Lag(:SliderID, 1)", the value of the comparison will be "True" and therefore it will return a numeric value of 1. If the comparison of the current row's value of SliderID is not equal to the previous row's value of SliderID, the returned value will be a 0.

@stephen_pearson modification of turning the formula into an "If" clause will result in the same values.

The error that is listed out, is a response to the line

```
dABCR << Delete Rows;
```

and it is being returned, because no rows had been selected as a result of the line

```
dABCR << Select Where(SN == 1);
```

The only correction to this line would be to scope the column reference by placing a ":" in front of SN

` dABCR << Select Where(:SN==1);`

Jim

5 REPLIES

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

Nov 6, 2017 1:59 AM
(2045 views)

Your formula is missing an if statement. It should be something like

`Formula(If(:sliderID == lag(:sliderID,1),1,0))`

I would recommend you get all the steps working by using the menus and mouse clicks before trying to script it.

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

Nov 6, 2017 4:08 AM
(2038 views)

Your formula

```
:SliderID == Lag(:SiiderID, 1 )
```

is a boolean operation. When the current rows value of SliderID is equal to the previous row's value os SliderID, "Lag(:SliderID, 1)", the value of the comparison will be "True" and therefore it will return a numeric value of 1. If the comparison of the current row's value of SliderID is not equal to the previous row's value of SliderID, the returned value will be a 0.

@stephen_pearson modification of turning the formula into an "If" clause will result in the same values.

The error that is listed out, is a response to the line

```
dABCR << Delete Rows;
```

and it is being returned, because no rows had been selected as a result of the line

```
dABCR << Select Where(SN == 1);
```

The only correction to this line would be to scope the column reference by placing a ":" in front of SN

` dABCR << Select Where(:SN==1);`

Jim

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

Nov 6, 2017 5:53 AM
(1058 views)

Looking at the data, I don't see any repeated SliderID values, so it might be working correctly. You might use

`try(dABCE<<DeleteRows) `

to catch and ignore the error when there is nothing to delete.

edit: well, not try, if it isn't throwing an error. Maybe this.

Craige

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

Nov 14, 2017 11:56 PM
(945 views)

that was enlightening! appreciated the brief explanation on how the formula works! :)

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

Nov 14, 2017 11:54 PM
(946 views)