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
- :
- Re: What's wrong with below code

- 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:
Jan 8, 2020 12:30 AM
| Last Modified: Jan 8, 2020 4:37 AM
(868 views)

I've got errors on below code:

```
dt << New Column( "Stage",
If( Formula( Substr( :Column 9, 1, 2 ) ) == "CP",
Formula( Left( :Column 9, 3 ) ),
" "
)
);
```

I want to add a new Col named "Stage" besides a raw Column 9, if starts with CP get the 1st 3 letters else blank, but I've got errors

Unexpected end of input. Perhaps there is a missing "," or ")".

Trying to parse arguments of function "New Column".

Line 207 Column 3: ►

I suspect I use Formula in wrong way, might need help here

Column 9 | Stage |

NG | |

CP2-NAVI12 | CP2 |

CP1-NAVI12 | CP1 |

NG | |

CP2-NAVI12 | CP2 |

jerryspilTC

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

Created:
Jan 8, 2020 2:57 AM
| Last Modified: Jan 8, 2020 3:01 AM
(857 views)
| Posted in reply to message from jerryspilTC 01-08-2020

The issue with your code is that you are not understanding the Formula element from the New Column function. You seem to be approaching the problem thinking that each segment within your line of script that has a function, such as Substr() or Left() needs to be told that it is a formula. Actually, the entire line of jsl:

`If( Substr( :Column 9, 1, 2 ) == "CP", Left( :Column 9, 3 ), "" )`

is what needs to be declared as the formula for the new column. Thus the New Column() function needs to be specified as:

```
dt << New Column( "Stage",
Character,
"Nominal",
Formula( If( Substr( :Column 9, 1, 2 ) == "CP", Left( :Column 9, 3 ), "" ) )
);
```

Jim

2 REPLIES 2

Highlighted

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

Created:
Jan 8, 2020 2:57 AM
| Last Modified: Jan 8, 2020 3:01 AM
(858 views)
| Posted in reply to message from jerryspilTC 01-08-2020

The issue with your code is that you are not understanding the Formula element from the New Column function. You seem to be approaching the problem thinking that each segment within your line of script that has a function, such as Substr() or Left() needs to be told that it is a formula. Actually, the entire line of jsl:

`If( Substr( :Column 9, 1, 2 ) == "CP", Left( :Column 9, 3 ), "" )`

is what needs to be declared as the formula for the new column. Thus the New Column() function needs to be specified as:

```
dt << New Column( "Stage",
Character,
"Nominal",
Formula( If( Substr( :Column 9, 1, 2 ) == "CP", Left( :Column 9, 3 ), "" ) )
);
```

Jim

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

Re: What's wrong with below code

Thanks Jim, Got it

jerryspilTC

Article Labels

There are no labels assigned to this post.