Subscribe Bookmark RSS Feed

Script Issue: Variable Names Not Passed Dynamically to Conditional Evaluation Statements

brandon_foster5

Community Trekker

Joined:

May 23, 2015

Hi Everyone,

I’m having some trouble drafting a script that will save me hours of time with some DOE analyses we are doing on a regular basis.

Here’s what I want the script to do:

1) Create a new variable for every original variable in the cc = {Variables} command that you can find in the script. THIS WORKS FINE.

2) For each new variable created I want to attach a conditional statement that will evaluate whether or not the data contained in the original variable is above some threshold value.

I feel like I’m getting close, the issue is that within the conditional statement the actual name of the variable in the cc command is not being passed properly. Therefore, my script errors out.

If you could be so gracious I’d like to understand better what is going wrong here. To aid I’ve attached some simulated data and the current script I am working on.

Also, I want to just make sure that within a script it is ok to pass multiple conditional statements on to multiple variables.

Thank you very much for any assistance in helping me learn from this issue.

Script (also attached as well as data)

cd = Current Data Table();

// User specified column names

cc = {C1 RLU, C2 RLU, C3 RLU};

For( i = 1, i <= N Items(cc), i++,

  New Column(Char(cc[i]) || "5e3" , Numeric, formula(IF (cc[i] > 5000, 1, 0)));

  (New Column(Char(cc[i]) || "1e4" , Numeric )); 10000 // if first conditional worked a second would be created here for 10000

  (New Column(Char(cc[i]) || "2e4" , Numeric ))); 20000 // another conditional here for 20000

1 ACCEPTED SOLUTION

Accepted Solutions
Solution

Try this script:

cd = Current Data Table();

// User specified column names

cc = { C1 RLU, C2 RLU, C3 RLU };

For( i = 1, i <= N Items( cc ), i++,

  cd << New Column( Char( cc[i] ) || " 5e3",

  Numeric,

  Values(

  Local( { data },

  data = cc[i] << Get As Matrix;

  data > 5000

  )

  )

  );

  cd << New Column( Char( cc[i] ) || " 1e4",

  Numeric,

  Values(

  Local( { data },

  data = cc[i] << Get As Matrix;

  data > 10000

  )

  )

  );

  cd << New Column( Char( cc[i] ) || " 2e4",

  Numeric,

  Values(

  Local( { data },

  data = cc[i] << Get As Matrix;

  data > 20000

  )

  )

  );

);

Learn it once, use it forever!
3 REPLIES
Solution

Try this script:

cd = Current Data Table();

// User specified column names

cc = { C1 RLU, C2 RLU, C3 RLU };

For( i = 1, i <= N Items( cc ), i++,

  cd << New Column( Char( cc[i] ) || " 5e3",

  Numeric,

  Values(

  Local( { data },

  data = cc[i] << Get As Matrix;

  data > 5000

  )

  )

  );

  cd << New Column( Char( cc[i] ) || " 1e4",

  Numeric,

  Values(

  Local( { data },

  data = cc[i] << Get As Matrix;

  data > 10000

  )

  )

  );

  cd << New Column( Char( cc[i] ) || " 2e4",

  Numeric,

  Values(

  Local( { data },

  data = cc[i] << Get As Matrix;

  data > 20000

  )

  )

  );

);

Learn it once, use it forever!
Jeff_Perkinson

Community Manager

Joined:

Jun 23, 2011

MarkBailey's answer is a good one.

If you still want columns with formulas the trick is to remember that JMP assumes the formula should be evaluated in the column, not at the time of script execution. As a result, it puts cc[1] in the formula instead of the column reference. You need to substitute the column reference in before evaluating the New Column().


cd = Current Data Table();


// User specified column names


cc = {C1 RLU, C2 RLU, C3 RLU};


For( i = 1, i <= N Items( cc ), i++,



  Eval(


       Substitute(


            Expr(


                 New Column( Char( cc[i] ) || "5e3", Numeric, formula( col > 5000 ) );


                 New Column( Char( cc[i] ) || "1e4", Numeric, formula( col > 10000 ) );


                 New Column( Char( cc[i] ) || "2e4", Numeric, formula( col > 20000 ) );


            ),


            expr(col), cc[1]


       )


  );



);


-Jeff

-Jeff
brandon_foster5

Community Trekker

Joined:

May 23, 2015

I just want to thank you both very much for your help. This fixed it, but more importantly I'll know how to problem solve through this kind of issue at a later date.

Very much appreciated.