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
- :
- Discussions
- :
- Re: Issue with JMP scripting (Multiply function)

Topic Options

- Start Article
- 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

Feb 18, 2019 6:37 AM
(1596 views)

Hi,

I'm having trouble using the multiply function in jmp, I wanting to evalute the values before I place them in a table. I have used the debug script and the two variables are evaluating correctly but not multiplying together. Can anyone help?

```
fl = Files In Directory( cal_path, recursive );
fli = {};
for( y = 1, y<=nitems(fl), y++,
if(left(fl[y],1) == "~", remove from(fl, y));
insertinto(fli,left(substitute(substitute(fl[y],"-",""),"_",""),9));
);
grfactor1 = {};
adjgr1 = {};
agr1 = {};
For( i = 1, i <= N Items( fl ), i++,
currentfile = cal_path || fl[i];
dt = Open( currentfile );
Current Data Table( dt );
name_list = dt << get column names( string );
If( Contains( name_list, "Active Multi" ) == 0 ,
Insert Into( grfactor1, "" );
Insert Into( adjgr1, "" );
close(dt, nosave);
Continue()
);
grfa = :name( "Active Multi 2" )[8];
adjgra = :name( "Active Multi 2" )[20];
Insert Into( grfactor1, grfa );
Insert Into( adjgr1, adjgra );
Close( dt, nosave );
);
agr1=adjgr1;
Multiply to (agr1, grfactor1);
ct = New Table( "historical_data" );
ct << New Column( "GRF1", numeric, values( Eval( grfactor1 ) ) );
ct << New Column( "GRU1", numeric, values( Eval( adjgr1 ) ) );
ct << New Column( "GR1", numeric, formula( GRU1 * GRF1 ) );
ct << new column( "check 1", numeric, values(Eval ( agr1 )));
```

Thank you in advance.

Tim

2 ACCEPTED SOLUTIONS

Accepted Solutions

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

I think your code is trying to do something like this; I had not tried a list of values before:

```
a={1,2};
b={3,4};
show(a,b);
c=multiplyto(a,b);
show(a,b,c);
```

a = {1, 2}; // input to multiply to()

b = {3, 4};

a = {3, 8}; // this is updated by multiply to()

b = {3, 4};

c = {3, 8}; // this is returned by multiply to()

Be sure to check the JMP log for error messages, and use the show(a,b) function to write some values to the log to see what is happening.

Craige

Highlighted

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

It looks like strings in this example, not numbers. If that's the case also for your data, you'll need to convert into numbers as strings will not multiply correctly. The conversion can probably be done efficiently in your loop:

```
//...
grfa = Num(:name("Active Multi 2")[8]);
adjgra = Num(:name("Active Multi 2")[20]);
//...
```

6 REPLIES 6

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

Re: Issue with JMP scripting (Multiply function)

Try to use the scoping ":" to indicate that GRU1 and GRF1 are column names. If the table is big it may also help to insert a Wait() command to allow the input columns the be fully finilized before the formula is evaluated.

```
//...
Wait(0);
ct << New Column("GR1", numeric, formula(:GRU1 * :GRF1));
//...
```

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

Re: Issue with JMP scripting (Multiply function)

I'm trying to remove the column calculation and calculate it in the scripting instead. The formula in the new column script work and is evaluatig correctly its the

`Multiply to (agr1, grfactor1);`

which should give me the same value but only seems to evaluate the variable to the agr1 value.

Tim

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

I think your code is trying to do something like this; I had not tried a list of values before:

```
a={1,2};
b={3,4};
show(a,b);
c=multiplyto(a,b);
show(a,b,c);
```

a = {1, 2}; // input to multiply to()

b = {3, 4};

a = {3, 8}; // this is updated by multiply to()

b = {3, 4};

c = {3, 8}; // this is returned by multiply to()

Be sure to check the JMP log for error messages, and use the show(a,b) function to write some values to the log to see what is happening.

Craige

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

Re: Issue with JMP scripting (Multiply function)

That's exaclty what I'm trying to do and I have used the show function (great idea) and it has returned this:

adjgr = {"2.763", .};

grfactor = {"0.291", .};

agr = {"2.763", .};

adjgr = {"2.763", .};

grfactor = {"0.291", .};

I only have 2 files at the moment its reading from and 1 doesn't contain anything and the other just contains random numbers.

As you can see its only evaluating to the adjgr and doesn't multilply it by the grfactor.

Tim

Highlighted

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

It looks like strings in this example, not numbers. If that's the case also for your data, you'll need to convert into numbers as strings will not multiply correctly. The conversion can probably be done efficiently in your loop:

```
//...
grfa = Num(:name("Active Multi 2")[8]);
adjgra = Num(:name("Active Multi 2")[20]);
//...
```

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

Re: Issue with JMP scripting (Multiply function)

Perfect, Thank you all. It's now working as expected.

Tim