cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Sign-in to the JMP Community will be unavailable intermittently Dec. 6-7 due to a system update. Thank you for your understanding!
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.
  • JMP 19 is here! Learn more about the new features.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
Françoise
Level VI

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
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
cwillden
Super User (Alumni)

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

Recommended Articles