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

Iterating Across Rows

Started ‎11-08-2022 by
Modified ‎11-08-2022 by
View Fullscreen Exit Fullscreen

In this demonstration, we'll see how to iterate across rows using the for each row function. So I'm going to get the Big Class data from the script in section And I'm going to write a script that's going to create a new column with the BMI, or Body Mass Index, values. And I'll use the for each row function to populate that. And the body mass index is calculated by multiplying the weight in pounds by and then dividing by the square of height, which is in inches here. So I'll use Ctrl+T to get a new script editor window. And I just want to rearrange these windows so that we can see the data table in the background, the log, and the script. I'm going to send the message to the current data table. And I'm going to spell current correctly. Now it turned blue. So the fact that it didn't turn blue helped me see that I had that typo. So I send the message New column. And in parentheses, the required argument for new column is the title. And I'll put the semicolon. And then I'll go to a new line and type for each row. And again, I'm going to let JMP capitalize everything for me. For each row, colon, BMI. So I'm using that colon scoping operator. And I will assign to that the result of the BMI computation. Which, in the numerator, I'll open parentheses there. We have colon weight times divided by. And I'll use parentheses to isolate the denominator. Although, the order of operations don't require this. I'll have the colon height raised to power of And then I'll go ahead and reformat. So that just put those spaces in, capitalized built-in names for me. And then I'll run the script. And so you can see in the table in the background that the column BMI has been created and then populated. Now, I could have also specified a format, a fixed decimal format, for example, when I created the column, or I could send that as a message after the fact. For our purposes, I won't do any other refinements on it. But I also will point out that, if I wanted to work with this column going forward, I could have also stored the result of this first line in a variable and used that variable rather than typing out the column name any time I wanted to send a message. So here, you saw the use of for each row to iterate down the rows of a data table to populate it without using a formula.