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

Showing results for

- JMP User Community
- :
- Discussions
- :
- set a formula for columns with variable name

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

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

Aug 3, 2015 10:07 AM
(1380 views)

I have 3 columns with variable names.

how can I add new column and give it a formula by use of a,b, and c?

I wrote following script but column doesn't show the formula.

New Column**(** "a /b",Numeric,Continuous,Format**(** "Best", **12** **)**,

Formula**(** :column**(**char**(a****))** / :column**(** char**(b****))** **))**;

thank you for your recommendation

1 ACCEPTED SOLUTION

Accepted Solutions

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

Solution

Ah OK. Here's a better example:

a = **10**;

b = **20**;

dt = New Table**(** "Example", Add Rows**(** **3** **)**,

New Column**(** char**(**a**)**, Numeric, Continuous, Format**(** "Best", **12** **)**,

Set Values**(** **[****1**, **2**, **3]** **)** **)**,

New Column**(** char**(**b**)**, Numeric, Continuous, Format**(** "Best", **12** **)**,

Set Values**(** **[****4**, **5**, **6]** **)** **)**,

**)**;

new_expr = evalinsert**(**

"\[dt << New Column( "a/b", Numeric, Continuous, Format( "Best", 12 ),

Formula( :Name( "^a^" ) / :Name( "^b^" )))]\"**)**;

eval**(**parse**(**new_expr**))**;

6 REPLIES

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

Aug 3, 2015 11:39 AM
(996 views)

This will work:

a = "weight";

b = "height";

dt = open**(**"$sample_data\Big Class.jmp"**)**;

new_expr = evalinsert**(**

"\[dt << New Column( "a/b",Numeric,Continuous,Format( "Best", 12 ),

Formula( :^a^ / :^b^ ))]\"**)**;

eval**(**parse**(**new_expr**))**;

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

Aug 3, 2015 11:49 AM
(996 views)

My "a" and "b" are not name; thay are numbers.

do I need any changes for that? because I tried your script, it didn't work for me.

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

Ah OK. Here's a better example:

a = **10**;

b = **20**;

dt = New Table**(** "Example", Add Rows**(** **3** **)**,

New Column**(** char**(**a**)**, Numeric, Continuous, Format**(** "Best", **12** **)**,

Set Values**(** **[****1**, **2**, **3]** **)** **)**,

New Column**(** char**(**b**)**, Numeric, Continuous, Format**(** "Best", **12** **)**,

Set Values**(** **[****4**, **5**, **6]** **)** **)**,

**)**;

new_expr = evalinsert**(**

"\[dt << New Column( "a/b", Numeric, Continuous, Format( "Best", 12 ),

Formula( :Name( "^a^" ) / :Name( "^b^" )))]\"**)**;

eval**(**parse**(**new_expr**))**;

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

Aug 3, 2015 1:35 PM
(996 views)

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

Aug 3, 2015 1:45 PM
(996 views)

For those not familiar with evalinsert or \[...]\:

**evalinsert** allows the insertion of variables surrounded by the caret character "**^**". Makes it easier to build a string containing variables by avoiding lots of concatenating.

The special characters **\[** in a string tell JMP not to interpret anything in the string, until you see the characters **]\**. Allows for clean insertion of double quotes, among other things.

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

Aug 3, 2015 1:28 PM
(996 views)

Hello, Razmah.

If all you want is to insert a new column to an already open file, with a formula using "A", "B, and "C" columns [from your data table], just run a similar script on your Script Editor:

New Column( "A/B", Numeric, Continuous, Format( "Best", 5 ), Formula( a / b ) );

New Column( "B/C", Numeric, Continuous, Format( "Best", 5 ), Formula( b / c ) );

New Column( "C*D", Numeric, Continuous, Format( "Best", 5 ), Formula( c * d ) );

New Column( "A+C+B", Numeric, Continuous,Format( "Best", 5 ),Formula( a + b + c));

Your script is missing the "Formula ( ) " function.

-Jose