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

- JMP User Community
- :
- Discussions
- :
- In For loop, Creating new column i, add formula using i in column name

- 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

Created:
Oct 25, 2019 2:06 PM
| Last Modified: Oct 28, 2019 5:06 AM
(1766 views)

As below, but it doesn't work, any thouhgts will be appreciated.

The goal is to call Jame's speed from 5 different tests, and compare to criteria.

```
For( i = 1, i <= 5, i++,
dt << New Column( "Jame" || Char( i ),
Character,
"Nominal",
Formula(
If( 100 > Column( "Jame_Speed_5*i" ) > 8,
"Pass",
"fail"
)
)
)
);
```

1 ACCEPTED SOLUTION

Accepted Solutions

Highlighted

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

The formula component of New Column will not work correctly the way you have it set up. First, the value of "i" needs to be concatenated to the literal string "Jame_Speed_5". Secondly, the fromula component will not parse and evalueate the concatenation, it will just assume that it is part of the formula, thus the Substitution needs to be used to completly build the formula before the New Column statement is parsed. Thirdly, the column name of "Jame_Speed_5*1" will be interpreted by JMP as a calculation, not a column name. Therefore, the :Name() function needs to be used to specify to JMP that it is a name, not a calculation. See below:

```
For( i = 1, i <= 5, i++,
Eval(
Substitute(
Expr(
dt << New Column( "Jame" || Char( i ),
Character,
"Nominal",
Formula(
If( 100 > __speed__ > 8,
"Pass",
"fail"
)
)
);
),
Expr( __speed__ ), Parse( ":Name(\!"Jame_Speed_5*" || Char( i ) || "\!")" )
)
)
);
```

Jim

4 REPLIES 4

Highlighted
##

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

Re: In For loop, Creating new column i, add formula using i in column name

The current error is,

when call the 1st speed result, "Jame_Speed_5*i" , the i can not be recognized at 1, etc.

when call the 1st speed result, "Jame_Speed_5*i" , the i can not be recognized at 1, etc.

Highlighted
##

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

Re: In For loop, Creating new column i, add formula using i in column name

There are 5 different columns naming as:

Jame_Speed_5*1

Jame_Speed_5*2

Jame_Speed_5*3

Jame_Speed_5*4

Jame_Speed_5*5

I hope to commpare each speed and give the results for each corrsponding column.

Highlighted

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

The formula component of New Column will not work correctly the way you have it set up. First, the value of "i" needs to be concatenated to the literal string "Jame_Speed_5". Secondly, the fromula component will not parse and evalueate the concatenation, it will just assume that it is part of the formula, thus the Substitution needs to be used to completly build the formula before the New Column statement is parsed. Thirdly, the column name of "Jame_Speed_5*1" will be interpreted by JMP as a calculation, not a column name. Therefore, the :Name() function needs to be used to specify to JMP that it is a name, not a calculation. See below:

```
For( i = 1, i <= 5, i++,
Eval(
Substitute(
Expr(
dt << New Column( "Jame" || Char( i ),
Character,
"Nominal",
Formula(
If( 100 > __speed__ > 8,
"Pass",
"fail"
)
)
);
),
Expr( __speed__ ), Parse( ":Name(\!"Jame_Speed_5*" || Char( i ) || "\!")" )
)
)
);
```

Jim

Highlighted
##

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

Re: In For loop, Creating new column i, add formula using i in column name

Thanks very much

@txnelson wrote:The formula component of New Column will not work correctly the way you have it set up. First, the value of "i" needs to be concatenated to the literal string "Jame_Speed_5". Secondly, the fromula component will not parse and evalueate the concatenation, it will just assume that it is part of the formula, thus the Substitution needs to be used to completly build the formula before the New Column statement is parsed. Thirdly, the column name of "Jame_Speed_5*1" will be interpreted by JMP as a calculation, not a column name. Therefore, the :Name() function needs to be used to specify to JMP that it is a name, not a calculation. See below:

`For( i = 1, i <= 5, i++, Eval( Substitute( Expr( dt << New Column( "Jame" || Char( i ), Character, "Nominal", Formula( If( 100 > __speed__ > 8, "Pass", "fail" ) ) ); ), Expr( __speed__ ), Parse( ":Name(\!"Jame_Speed_5*" || Char( i ) || "\!")" ) ) ) );`

Article Labels

There are no labels assigned to this post.