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
aumair
Level III

Using loops in formula

Hi, 

 

Is it possible to use loop in the column formula? For example, I have a column named  TEST, and I write for (i=1, i<5, i++, :TEST=char(i)) ... but I do not get anything, that column is blank after I hit apply/OK. From the loop I am hoping to get every row in the column would be 4.

 

 

Sorry for asking such a simple question, but coluldn't find the answer by quickly going thru appendix A of "Using JMP" manual.

 

Thanks,
Ahmad

7 REPLIES 7
aumair
Level III

Re: Using loops in formula

No need to reply....found out the issue, thanks! Assignment should be outside the loop.

gronk
Level I

Re: Using loops in formula

Hi, I am trying to use loops in the column formula for the first time, and I seem to be running into your original problem. 

Could you clarify how you solved the issue, and what you meant by the assignment should be outside the loop?

Thanks!  

txnelson
Super User

Re: Using loops in formula

What is your specific issue.  Can you post what formula you are currently using that isn't working for you?

Jim
gronk
Level I

Re: Using loops in formula

Thank you very much for your reply. 

 

The final problem I'm trying to solve is the following: I have stress-strain data for multiple test strips for multiple formulations (please see the attached JMP data file). The attached table contains 4 different formulation+strip "groups" i.e) FormA/strip1, FormA/strip2, FormB/strip1, FormB/strip2... For each group, I need to identify 1) the maximum stress (tensile strength) and 2) the strain associated with the maximum stress. To identify the maximum stress, I created a column "Tensile Strength" and used simply used "Col Max()" in the Formula Editor (see image below)    

gronk_1-1603595768574.png

Now, I'm looking to populate the "%elongation" column with the strain values associated with the maximum stress (tensile strength) for each group, and this is where my issue liesRather than going through the table to manually identify these strain values and populate the "%elongation" column, I'm wondering if there's a way to accomplish this with a column formula (or JSL script).

I was thinking this may involve a combination of loops and/or conditional functions.

 

Initially, I experimented with iterating through the "Stress" column with a for loop, to check if Stress=Tensile Strength in a given row (if yes, then populate the "%elongation" column with the associated strain value). Please see the attached JPG file "stress-strain data_jmp community help_iteration attempt" for the initial column formula/attempt. The column remained unchanged/blank.

I then tried to simply populate the first 5 rows in the "%elongation" column with the strain values in the given rows (please see the attached JPG file "stress-strain data_jmp community help_for loop"). The column remained blank, and this is what prompted my initial post. I'm assuming there are key errors in how I'm using the functions.

**Moreover, I recognize that my initial formula is far too simplistic for my final goal.

 

Apologies for the lengthy post and if I was unclear with anything. I'd be happy to provide any clarification. I'm quite new to JMP, thus any advice/help with this would be greatly appreciated. Thank you in advance. 

txnelson
Super User

Re: Using loops in formula

Here is a formula for the creation of %elongation.  It is not a very efficient formula, but it will find the value regardless of the order of the data. 

curForm = :Formulation;
curStrip = :Strip;
theRow = (Current Data Table() << get rows where(
	:Formulation == curForm & :Strip == curStrip & :Stress == :Tensile Strength
))[1];
:Strain[theRow];

If the data are sorted by Formulation and Strip, then the more efficient formula below can be used.

If( Row() == 1 | :Formulation != Lag( :Formulation ) | :Strip != Lag( :Strip ),
	curForm = :Formulation;
	curStrip = :Strip;
	theRow = (Current Data Table() << get rows where(
		:Formulation == curForm & :Strip == curStrip & :Stress == :Tensile Strength
	))[1];
);
:Strain[theRow];
Jim
gronk
Level I

Re: Using loops in formula

Thanks so much for your help/response.  

In regards to the simple for loop I used to try to populate the first five rows in the "%elongation" column, I'm curious why the column remains unchanged/blank. Am I completely off the mark in how I used the formula and/or defined the arguments?

In the very early stages of learning JMP and JSL, trying to learn from my mistakes. 

 

Thanks again for the help!

txnelson
Super User

Re: Using loops in formula

I do think your current understanding of formula usage is in error.  I am particularly confused with what your  expected results for the formula

For( i=0, i<=5, i++, :Strain )

 By default, formulas are run once for each row.  Therefore, most of the time a For() loop would not be used.

I  have attached a data table with 4 different formulas applied.  I am hoping that if you look at the different formulas, that it will help you adjust your understanding of how formulas work.

Jim