cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP 19 is here! See the new features at jmp.com/new.
  • Register to attend Discovery Summit 2025 Online: Early Users Edition, Sept. 24-25.
Choose Language Hide Translation Bar
lala
Level IX

Can the calculations of these two steps be modified to be completed in one step?

Thanks Experts!

dt=Open("$SAMPLE_DATA/Big Class.jmp");
ca="A";If(Is Missing(Try(Column(ca)<<Get Name)),New Column(ca));Column(ca)<<Formula( if(height>=lag(height,1),weight) );Current Data Table()<<run formulas;Column(ca)<<deleteFormula;
ca="B";If(Is Missing(Try(Column(ca)<<Get Name)),New Column(ca));Column(ca)<<Formula( if(height<lag(height,1),weight) );Current Data Table()<<run formulas;Column(ca)<<deleteFormula;
ca="C";If(Is Missing(Try(Column(ca)<<Get Name)),New Column(ca));Column(ca)<<Formula( if(row()>9,round(sum(A[Index(Row()-9,Row())])/sum(B[Index(Row()-9,Row())]),2) ));Current Data Table()<<run formulas;Column(ca)<<deleteFormula;

ca="D";If(Is Missing(Try(Column(ca)<<Get Name)),New Column(ca));Column(ca)<<Formula(  if(row()>9,sum(weight[Index(Row()-9,Row())]&height[Index(Row()-9,Row())]>=height[Index(Row()-10,Row()-1)])/sum(weight[Index(Row()-9,Row())]&height[Index(Row()-9,Row())]<height[Index(Row()-10,Row()-1)])) );Current Data Table()<<run formulas;Column(ca)<<deleteFormula;

2025-09-21_17-40-41.png

3 REPLIES 3
Craige_Hales
Super User

Re: Can the calculations of these two steps be modified to be completed in one step?

(assuming your goal is either speed, or easier to read code...)

 

Column formulas are not magic. They are not faster than JSL. They are JSL.

OK, they can be a little bit magic; JMP's engine that evaluates columns does figure out which columns are dependent on other columns and evaluate the not-dependent formulas first. But that never happens here since the formulas are deleted.

 

Since you are creating / running / deleting the formula to populate a column, four times, you might want to try a single JSL loop with the four inner statements inside. Be sure to use the <<beginDataUpdate before the loop and <<endDataUpdate after the loop. I don't expect this to be a lot faster, but it might be a lot easier to read. (Your example has some repeated computations that could be streamlined in a single loop.) You can probably use ForEachRow(dt, ... ) and get the same looping speed that <<runformulas has.

 

Craige
hogi
Level XII

Re: Can the calculations of these two steps be modified to be completed in one step?

none of the weights is empty.

weight[Index(Row()-9,Row())]&height[Index(Row()-9,Row())]>=height[Index(Row()-10,Row()-1)]

can be reduced to 
height[Index(Row()-9,Row())]>=height[Index(Row()-10,Row()-1)]

or maybe: you wanted to calculate something else?

selection of A & B.
comparison of C&D

hogi_0-1758459727481.png


let's challenge it:
a)

weight[11] = 500;


b)

current data table()<< add rows(10);
height[41::50] = 70;
weight[41::50] = 1;

 

lala
Level IX

Re: Can the calculations of these two steps be modified to be completed in one step?

I need this form composed of several formulas and don't want any loops in it.
Thanks Experts!

aaa="";
current data table(dt);Eval(Parse("Column(dt,\!"ABC\!")<<Formula("||aaa||")"));dt<<run formulas;Column("ABC")<<deleteFormula;s=N Rows(Loc(dt[0,"ABC"]>0));

Recommended Articles