Choose Language Hide Translation Bar
Highlighted

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

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

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

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

## 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.
Highlighted

## 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

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

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

## 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.