Subscribe Bookmark RSS Feed

JMP script question

hy

Community Trekker

Joined:

Jul 10, 2011

I'm a new user trying to learn JMP script.  I've a very simple script but encountered an expected result.  May be someone can give me a pointer on what did I do wrong here.  Thanks in advance.  (BTW: I'm using JMP 8.02)

I have a very simple table as below (test1.csv):

Tool_firstTool_secondProcess_timeTool_thirdGroup_1Real_betaBase
AC4/3/2011 0:53EA-E0.0058Y
AC4/3/2011 1:08EA-E0.0058Y
AC4/3/2011 5:27EA-E0.0058Y
AC4/3/2011 6:26EA-E0.0058Y
AD4/3/2011 6:39EA-E0.0058Y
AC4/3/2011 6:49EA-E0.0058Y
AC4/3/2011 18:43EA-E0.0058Y
AC4/3/2011 23:42EA-E0.0058Y
AC4/4/2011 5:20EA-E0.0058Y
AC4/4/2011 8:34EA-E0.0058Y
AC4/4/2011 10:43EA-E0.0058Y
AD4/4/2011 11:02EA-E0.0058Y
AC4/4/2011 13:57EA-E0.0058Y
AC4/4/2011 14:28EA-E0.0058Y
AD4/4/2011 16:43EA-E0.0058Y
AC4/4/2011 20:01EA-E0.0058Y
AC4/4/2011 20:17EA-E0.0058Y
AD4/4/2011 21:45EA-E0.0058Y
AC4/5/2011 18:20EA-E0.0058Y
AD4/5/2011 20:02EA-E0.0058Y
AC4/5/2011 20:35EA-E0.0058Y

The following script reads in the .csv file and added two more columns to the table based on comparison of one row with its previous row.  My script is below

Source_Table=Open ("c:\test1.csv");

Source_Table <<Sort(By(group_1, process_time), order(Ascending), Replace Table);

new column("Inspect_pt",
formula(
if(row()==1,1,
(:group_1[row()] != :group_1[row()-1]),1,
(:group_1[row()] == :group_1[row()-1]),0)));

new column("tool_Change",
           formula(
                   if(row()==1,1,
                          (:tool_second[row()] != :tool_second[row()-1]),1,
                          (:tool_second[row()] == :tool_second[row()-1]),0
                      )
                   )
           );
show(current data table());

/* try to output the value of the last two columns */
for (i=1, i<n_row, i++, row()=i; show(i, row(),:inspect_pt,:tool_Change););

The result table is OK but the last line of the script did not return any result on the two newly created columns.  The log window showed the index becomes ::i.

Output table:

[Missing image]

But the log window showed the result of the last two columns not pulled correctly.  Did I used the wrong indexing?  Log window output here:

Current Data Table:DataTable("test1")

i:1

Row:1

:Inspect_pt[::i]:.    <-- this is not correct

:tool_Change[::i]:.  <-- this is not correct

i:2

Row:2

:Inspect_pt[::i]:.

:tool_Change[::i]:.

i:3

Row:3

:Inspect_pt[::i]:.

:tool_Change[::i]:.

i:4

Row:4

:Inspect_pt[::i]:.

:tool_Change[::i]:.

1 ACCEPTED SOLUTION

Accepted Solutions
pmroz

Super User

Joined:

Jun 23, 2011

Solution

Try "flushing" JMP's formula buffer with this statement:

Source_Table << run formulas;

Add this line after your formula definitions.

6 REPLIES
pmroz

Super User

Joined:

Jun 23, 2011

Solution

Try "flushing" JMP's formula buffer with this statement:

Source_Table << run formulas;

Add this line after your formula definitions.

hy

Community Trekker

Joined:

Jul 10, 2011

Thanks PMroz.  That did the trick.  For my own benefit, can you please elabrate what was going on and why the extra line is needed to get this to work.  Thanks again

pmroz

Super User

Joined:

Jun 23, 2011

Hi HY,

I'm not sure exactly why you need this statement - I got it from JMP tech support.  Perhaps someone from JMP could explain?

Regards,

Peter

MTOF

Community Trekker

Joined:

Jun 29, 2011

Hi

JMP doesn't finish one "command" before moving on to the next - it reads the 'new column' command and starts executing it, but continues to read and perform the next commands.

What happens here is that the 'New Column' commands are not finished executing (this type of command especially takes some time because the graphics have to be updated), before JMP reads the final line with the 'show' commands, so there are no values in the columns at the time this command is executed.

Either 'flush' the formulas as above or put a 'eval formula' directly into the 'new column' command, e.g.

new column("title", numeric, formula(:X1*:X2), eval formula);

As far as I have understood the two approaches have the same effect.

BR, Marianne

PS: I'm not from JMP

bgouaux

Community Trekker

Joined:

Jul 5, 2011

This becomes particularly important when writing scripts that use values from earlier processes for determining how to proceed (e.g. Select Where( :tool_change == 1) in order to subset).  By inserting a 'run formulas' line at the end of a block of code like this, you tell JMP to pause, evaluate all pending formulas, and then proceed with the rest of the script.

I'm not as familiar with the behavior of 'eval formula' (I typically use 'run formulas' - just a matter of habit), so this is speculation, but depending on the specific processes I could see situational differences that would favor 'eval formula' over 'run formulas' (i.e. where you only care about one formula for making a decision, you could instruct only that formula to evaluate, saving the remaining formula evaluations for later).  The difference here would really depend on how many formula evaluations you need to do and when you want them to be done.

hy

Community Trekker

Joined:

Jul 10, 2011

Thanks everyone on the valuable information.  This forum is great.