cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
timroberts90
Level II

Issue with JMP scripting (Multiply function)

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
Craige_Hales
Super User

Re: Issue with JMP scripting (Multiply function)

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

View solution in original post

ms
Super User (Alumni) ms
Super User (Alumni)

Re: Issue with JMP scripting (Multiply function)

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]);
//...

 

View solution in original post

6 REPLIES 6
ms
Super User (Alumni) ms
Super User (Alumni)

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));
//...
timroberts90
Level II

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
Craige_Hales
Super User

Re: Issue with JMP scripting (Multiply function)

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
timroberts90
Level II

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
ms
Super User (Alumni) ms
Super User (Alumni)

Re: Issue with JMP scripting (Multiply function)

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]);
//...

 

timroberts90
Level II

Re: Issue with JMP scripting (Multiply function)

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

Tim