BookmarkSubscribeRSS Feed
Choose Language Hide Translation Bar

Re: JSL: Creating formula using a variable column name

@mpb: That works fine! Thanks for finding out and for the book tip!
0 Kudos

Re: JSL: Creating formula using a variable column name

I tried but cant get it work on a variant.

There are two column where the user chooses in a custom dialog box, and i assign them the names of lx,ly.
I need a new column with formula

Radius = SQRT((X^2)+(Y^2))

However, when i run it, althought the new column is created, JMP prompt me
"N Items() argument must be a list", and no formula created.

Appreciate if a kind soul can advice on which part is faulty. Thanks.

customDlg << CloseWindow;
lp = colListP << GetItems;
lx = colListX << GetItems;
ly = colListY << GetItems;
 
// Are the user selections viable?
if (NItems(lp) < 1,
     Dialog("ERROR: Select one or more Parameter Columns", Button("OK")); Throw());
if (NItems(lx) != 1,
     Dialog("ERROR: You need to select an X Column", Button("OK")); Throw(),
     xVar = lx(1)     
     );
if (NItems(ly) != 1,
     Dialog("ERROR: You need to select a Y Column", Button("OK")); Throw(),
     yVar = ly(1)
     );
 
 
// *********************************************************************************
// Build New Column with new formula
// *********************************************************************************
 
dt = Current Data Table();
a = Column(dt,xvar);
b = Column(dt,yvar);
colx = ;
coly = ;
nlist = N Items(a);
For( i = 1, i <= nlist, i++,     
newColExpr = Expr(          
               dt << New Column( "Radius", Numeric,
               Formula( Root((Power(Expr(a(i)),2)+Power(Expr(b(i)),2)),2 ) )     );     
               Eval( Eval Expr( newColExpr ) );
);
);
); 
0 Kudos
mpb
Super User mpb
Super User

Re: JSL: Creating formula using a variable column name

Here's an example using the Column Dialog which gives the user the choice to select exactly 2 columns from which the Radius column will be created.

dt = Current Data Table();
cdlg = Column Dialog( clist = ColList( "Pick 2 Columns", Min Col( 2 ), Max Col( 2 ) ) );
cols = cdlg["clist"];
 
newColExpr = Expr( dt << New Column( "Radius", Numeric, Formula( Sqrt( Expr( cols&#91;1&#93; ) ^ 2 + Expr( cols&#91;2&#93; ) ^ 2 ) ) ) );
 
Eval( Eval Expr( newColExpr ) );
0 Kudos

Re: JSL: Creating formula using a variable column name

Thanks for the help. Will try it out.
=)
0 Kudos