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

- JMP User Community
- :
- Discussions
- :
- FOR () Loop Script not working

- 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

FOR () Loop Script not working

Created:
May 29, 2020 6:31 PM
| Last Modified: May 30, 2020 6:12 AM
(497 views)

I want to write a sequencing value to a new column after checking a condition (Time value) or a fixed set of rows.

Belo JMP script my script below creates a null value column.

```
Names Default To Here(1);
ROW = N ROW();
Run= New Column("Run", "numeric","ordinal");
n=1;
For(i = 1,
i<=ROW, i++,
If(:Time<1,i,i+1)
)
```

Any guidance from the community will be greatly appreciated.

3 REPLIES 3

Highlighted
##

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

Re: FOR () Loop Script not working

Here is a simple script, that creates a :Time column, and then generates what I believe you are specifying should be your :Run column. I generate the :Run column using 3 different methods. You can read about all of this in the Scripting Guide

Help==>JMP Documentation Library...……….Scripting Guide

```
Names Default To Here( 1 );
dt = New Table( "Example",
add rows( 20 ),
New Column( "Time", formula( Random Uniform( .5, 1.5 ) ) )
);
dt << New Column( "Run1",
"numeric",
"ordinal",
formula( If( :Time < 1, Row(), Row() + 1 ) )
);
dt << New Column( "Run2", numeric, ordinal );
For( i = 1, i <= N Rows( dt ), i++,
If( :Time[i] < 1,
:Run2[i] = i,
:Run2[i] = i + 1
)
);
dt << New Column( "Run3", numeric, ordinal );
For Each Row(
If( :Time < 1,
:Run3 = Row(),
:Run3 = Row() + 1
)
);
```

Jim

Highlighted
##

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

Re: FOR () Loop Script not working

Thank You for your prompt guidance. Script partially worked. My time is in sequence and logic is assigning a new number to every row.

To make it simple, how do I create a column that counts rows up to 1 sec or 10 rows and assigns a number and repeats the process until the end of the table.

Thank You for your help!

Highlighted
##

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

Re: FOR () Loop Script not working

I believe the example below does what you want

```
Names Default To Here( 1 );
dt = New Table( "Example",
add rows( 50 ),
New Column( "Time",
formula( Today() + Random Uniform( 10, 20. ) ),
Format( "h:m:s", 11, 2 )
)
);
dt << run formulas;
dt:time << delete formula;
dt << sort( by( :time ), order( ascending ), replace table( 1 ) );
dt << New Column( "Sequence",
formula(
If( Row() == 1,
start = :time;
count = 0;
);
If( count >= 10 | :Time - Start > 1,
start = :time;
count = 0;
);
count = count + 1;
)
);
```

Jim