Subscribe Bookmark RSS Feed

Cannot create a column formula dynamicly

jefftheoptoguy

Community Trekker

Joined:

May 31, 2012

I am an intermediate user and I am trying to create 50 columns with unique formulas based product specs.

I have succeesfuly created a strng variable withthe formula in it but I cannot get inot the column in a manner that works:

When I view the variable min_Form it shows the exact formula that I want to insert but when I inert it the column formula shows "min_form" and not the actual string that I was hoping for.

Any ideas on how to get the contents of the variable inserted instead of the variable name?

//Need to create formulas as character strings before inerting into formula field of new column

  Minspec=char(":" || char(temp_Srow) || "_MinMarg");

  maxspec=char(":" || char(temp_Srow) || "_MaxMarg");

 

  min_Form="If(" || maxspec ||" < 0 | " || Minspec  || " < 0,1,

         Empty()

        );

       )";

      

  // Max Only

   if (is missing(temp_SpecMin),

    dtMM<< New Column(Char(temp_Mcol() || "_Fail"),

     character,

     formula(min_Form)

     );

     matchflag = 1;

     Break(); // Go to next spec

   );

Thank you in advance,

Jeff


4 REPLIES
pmroz

Super User

Joined:

Jun 23, 2011

Here's one way to do it.  Basically you build the entire new column expression and run it through eval(parse()).

dt = open("$sample_data\big class.jmp");

my_formula = ":Age * :Height / :Weight";

new_column_expr = "dt << new column(\!"Test\!", numeric, continuous, formula(" || my_formula || "))";

eval(parse(new_column_expr));

jefftheoptoguy

Community Trekker

Joined:

May 31, 2012

Thanks PMroz,

I am almost done.

I can get the formula in now.

The last issue I am having is in formatting the text true result in my if statement:

="If(" || maxspec ||" < 0 | " || Minspec  || " < 0," || temp_Srow || ",Empty());";

The issue is the caracter string temp_Srow.

assume temp_srow="Hi"

I want it to show up as "Hi" in the results but it shows up as Hi without the quotes and when I use \! around it I get "temp_srow" in the formula result.

Thanks,

Jeff

adamrauk

Community Trekker

Joined:

Mar 5, 2012

Try adding an extra quotation outside temp_Srow with \!:

"If(" || maxspec ||" < 0 | " || Minspec  || " < 0,\!"" || temp_Srow || "\!",Empty());";

Adam

jefftheoptoguy

Community Trekker

Joined:

May 31, 2012

Adam,

That worked.

Thanks for your help!

Jeff