Problem
You want to add the same set of new, formula-based columns to your data over and over again.
Solution
Store the formulas and column names in a table. Extract them from that table. loop over them trying to make a new column for each pair in your target data table.
favorite_formulas=function({dt1=currentdatatable(),FFpath},{default local},
/*
adds formulas to a data table from another data table <BR />used to store column names and respective formulas
example: favorite_formulas(currentdatatable(),"my_formulas.jmp");
FFpath must point to a file with columns "formula" and "colname" <BR />with text of desired formulas and column names
in the order they should evaluate (row 3 can use the column created by row 2, etc)
*/
try( //open setup file and get list of formulas and column names
dtFF=open(FFpath);
current data table(dtFF);
dt1 << suppressFormulaEval(true);
try(c=:colname,<BR /> wait(0);statusmsg("setup file must contain column colname");<BR /> throw ("setup file must contain column colname"));
try(c=:formula,<BR /> wait(0);statusmsg("setup file must contain column formula");<BR /> throw("setup file must contain column formula"));
CN=column("colname")<<GETVALUES></GETVALUES>Discussion
I often pull data with the same columns and format and I want to add the same set of new formula columns each time. This is just a tidbit that makes that easy and makes it easy to share around sets of "favorite formulas" with other users as simple, readable datatables. I use this function version inside a lot of other scripts but I also have an addin version.
See Also
This functionality is directly supported by the Formula Depot, available in JMP Pro. Save your formulas from the table to the Depot using "Add Formula from Column", and later transfer them to a new table using "Run Scripts".
