cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
CrownofTears
Level II

Trying to create a column and fill it with a formula but I get an error.

View more...
Hi, I can make the script to fill the new column created.

This is the error I get:
 Has anyone an idea of whats wrong here?


Formula Interrupted
Cannot convert argument to a number [or matrix] at row 1 in access or evaluation of 'Subtract' , Column( j ) - /*###*/Column( j + 1 ) /*###*/
Formula evaluation errors have been ignored
For (j=3, j<=10, j=j+2,
	
	ColLen=Length(Char(Column name (j)));
	ColName=Left (Char(Column Name(j)),ColLen -5);
	NewCol=Substr(ColName,6);
	
	New Column(
		"Delta: "||NewCol,
		Numeric,	
		Formula (
			(Column (j)- Column(j+1))
		)
	)
);
13 REPLIES 13
CrownofTears
Level II

Re: Trying to create a column and fill it with a formula but I get an error.

Just As Column() instead of column worked!

mmarchandTSI
Level V

Re: Trying to create a column and fill it with a formula but I get an error.

@CrownofTears, Based on your original JSL:

 

For( j = 3, j <= 10, j = j + 2, 
	
	ColLen = Length( Char( Column Name( j ) ) );
	ColName = Left( Char( Column Name( j ) ), ColLen - 5 );
	NewCol = Substr( ColName, 6 );
	
	Eval(
		Eval Expr(
			New Column( "Delta: " || NewCol,
				Numeric,
				Formula( (As Column( Expr( Column Name( j ) ) ) - As Column( Expr( Column Name( j + 1 ) ) )) )
			)
		)
	);
);

I like the clean As Column("column name") functions, and it's not ugly like my Eval( Parse(...) ) solution.

CrownofTears
Level II

Re: Trying to create a column and fill it with a formula but I get an error.

Just As Column() instead of column worked!

hogi
Level XII

Re: Trying to create a column and fill it with a formula but I get an error.

Seems to work "once" (the values are OK)  - but (at least for my test case) variant #1 reports an error with the formula when you open it afterwards:

hogi_0-1691781905300.png

 

Variant # 6 seems to solve this issue:

hogi_1-1691782023921.png

but it will definitely fail once Jmp is closed and forgets what dt means ....