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

- 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:
Sep 10, 2019 2:27 PM
| Last Modified: Sep 10, 2019 2:32 PM
(2476 views)

Hi,

I am trying to define a new column formula from user input. I have tried different combinations of Eval(), Eval Insert(), and Parse() without success. Input can either be columns or lists of columns, plus a scalar. Below is a minimal example. Any suggestions? I am using JMP14, but I hope the solution will work for JMP12 and above.

```
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
// Define new column.
dt << New Column( "Mean for Each Age and Sex Group",
Formula( Col Mean( :height, :age, :sex ) )
);
// Define user input.
a = 2;
c1 = :height;
c2 = {:age, :sex};
// Define new column from user input.
dt << New Column( "Mean for Each Age and Sex Group 2",
Formula( Col Mean( a * c1, c2 ) )
);
```

- Tags:
- eval_insert
- parse

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

With help from @ih's input, here is a solution for anyone interested...

```
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
// Define user input.
a = 2;
c1 = Column( "height" );
c2 = {:age, :sex};
// Define new column from user input.
input = Concat( "As Column( \!"", c1 << Get Name, "\!" )" );
If( N Items( c2 ) > 0,
For( i = 1, i <= N Items( c2 ), i++,
input = Insert( input, Concat( ", ", "As Column( \!"", Char( c2[i] ), "\!" )" ) )
)
);
Eval( Parse( Eval Insert( "dt << New Column( \!"Mean for Each Age and Sex Group 2\!", Formula( ^a^ * Col Mean( ^input^ ) ) )" ) ) );
```

3 REPLIES 3

Highlighted
##

I am not totally sure what formula you want in the newly created column from user input, but take a look at this JSL Cookbook article, it gives examples of several different methods of constructing your new column formula.

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

Re: Define Column Formula from User Input

Highlighted
##

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

Re: Define Column Formula from User Input

Thanks! Very useful page.

Highlighted

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

With help from @ih's input, here is a solution for anyone interested...

```
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
// Define user input.
a = 2;
c1 = Column( "height" );
c2 = {:age, :sex};
// Define new column from user input.
input = Concat( "As Column( \!"", c1 << Get Name, "\!" )" );
If( N Items( c2 ) > 0,
For( i = 1, i <= N Items( c2 ), i++,
input = Insert( input, Concat( ", ", "As Column( \!"", Char( c2[i] ), "\!" )" ) )
)
);
Eval( Parse( Eval Insert( "dt << New Column( \!"Mean for Each Age and Sex Group 2\!", Formula( ^a^ * Col Mean( ^input^ ) ) )" ) ) );
```

Article Labels

There are no labels assigned to this post.