Share your ideas for the JMP Scripting Unsession at Discovery Summit by September 17th. We hope to see you there!
Choose Language Hide Translation Bar
Highlighted
Françoise
Level IV

column with formula in a post query script

hi,

 

With a JMP query builder, and with the post query script, I create a new column with something like this:

 

dt << NewColumn("BMI", Numeric, Continuous, Formula(:weight/:height^2));

but, my problem is: when I update from database the jmp file, I create a new column "BMI 2".

and with an another update: a new column BMI 3.

 

I would like to have only one column BMI at each update from database.

 

is it possible?

 

best regards

2 REPLIES 2
Highlighted
txnelson
Super User

Re: column with formula in a post query script

Without more specifics, it is tough to say precisly what the solution is, but my initial thought is that you need to check to see if the column you are creating already exists, and if it does, then you either need to delete the existing column and then create the new column, or just skip the creation of the new column.  I am not sure which of these is correct, not knowing the logic and flow of your script.

If( try( column(dt, "the column name" ) << get name, "" ) != "",
     dt << delete columns( "the column name" );
);

 

Jim
Highlighted
cwillden
Super User

Re: column with formula in a post query script

If I understand this correctly, you should be able to avoid creating new columns by checking first if the column exists before executing that line of code.  Here's a way to do it:

if(Contains(dt << Get Column Names(string),"BMI")==0,
	dt << NewColumn("BMI", Numeric, Continuous, Formula(:weight/:height^2));
);
-- Cameron Willden
Article Labels

    There are no labels assigned to this post.