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

- JMP User Community
- :
- Discussions
- :
- Error in loop to standarize numeric columns

- 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:
Jul 15, 2019 6:40 AM
| Last Modified: Jul 15, 2019 7:40 AM
(881 views)

Hi. I have written a script to create new numerical columns from the formula to standardize but I get an error when evaluating the formula. What do I do wrong?

Thank you.

**The script:**

```
Names Default To Here( 1 );
dt = Current Data Table();
numericColNames = dt << get column names( string, numeric );
For( i = 1, i <= N Items( numericColNames ), i++,
New Column( Char( numericColNames[i] ) || "_Stand",
Numeric,
Continuous,
Formula( Col Standardize( :numericColNames[i] ) ) )
);
```

**The error:**

Name Unresolved: numericColNames 1 times At rows: {1} Operation: numericColNames, :numericColNames

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

A column name like 1900 can confuse JMP, because it may not know if it should treat it as a number or a column name. So one needs to specifically indicate that it is a column name by using the :Name() function...see the reworked script below

```
Names Default To Here( 1 );
dt = Current Data Table();
numericColNames = dt << get column names( string, numeric );
numericColNames = {"1900"}
For( i = 1, i <= N Items( numericColNames ), i++,
Eval(
Substitute(
Expr(
New Column( Char( numericColNames[i] ) || "_Stand",
Numeric,
Continuous,
Formula( Col Standardize( __col__ ) )
)
),
Expr( __col__ ), Parse( ":Name(\!"" || numericColNames[i] || "\!")" )
)
)
);
```

Jim

Highlighted

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

Sir, you seem to have an answer for everything. Thanks again for your contribution!

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: Error in loop to standarize numeric columns

When you specify a formula value, it will not do any evaluation of the JSL for the formula. Rather, it will just move the code into the formula. So, what is being placed into the formula is " Col Standardize**(** :numericColNames**[**i**]** **)**", not, "Col Standardize**(** :YourColumnName **)". **So when the formula is executed, it will look for the value of "i", which by the time it executes, it has already moved beyone your subscript range for Colnames. So what needs to be done is to place the exact JSL syntax for the formula, into the formula.

```
Names Default To Here( 1 );
dt = Current Data Table();
numericColNames = dt << get column names( string, numeric );
For( i = 1, i <= N Items( numericColNames ), i++,
Eval(
Substitute(
Expr(
New Column( Char( numericColNames[i] ) || "_Stand",
Numeric,
Continuous,
Formula( Col Standardize( __col__ ) )
)
),
Expr( __col__ ), Parse( ":" || numericColNames[i] )
)
)
);
```

Jim

Highlighted
##

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

Re: Error in loop to standarize numeric columns

**(** string, numeric **)**;" recognizes the col 1900 and "Percentage Canvi" as numerics when creating the two new columns, the one corresponding to 1900 leaves it with missing values.

Highlighted

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

A column name like 1900 can confuse JMP, because it may not know if it should treat it as a number or a column name. So one needs to specifically indicate that it is a column name by using the :Name() function...see the reworked script below

```
Names Default To Here( 1 );
dt = Current Data Table();
numericColNames = dt << get column names( string, numeric );
numericColNames = {"1900"}
For( i = 1, i <= N Items( numericColNames ), i++,
Eval(
Substitute(
Expr(
New Column( Char( numericColNames[i] ) || "_Stand",
Numeric,
Continuous,
Formula( Col Standardize( __col__ ) )
)
),
Expr( __col__ ), Parse( ":Name(\!"" || numericColNames[i] || "\!")" )
)
)
);
```

Jim

Highlighted

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

Sir, you seem to have an answer for everything. Thanks again for your contribution!

Article Labels

There are no labels assigned to this post.