There seems to be some confusion on how to manipulate columns in a data table vs. working with JSL variables. Below is a script that uses 2 methods to create a subtraction of the values in column "BP 6M" with the values in column "BP 8M"
Method 1 creates column Norm_BP 6M, and method 2 creates column Norm2_BP 6M
I have annotated the JSL in hopes to help you understand what the 2 different approaches are doing
names default to here(1);
// Open a sample data table to use for illustration
dt =
// Open Data Table: Blood Pressure.jmp
// → Data Table( "Blood Pressure" )
Open( "$SAMPLE_DATA/Blood Pressure.jmp" );
// The data table has the following columns in it
// Subject, Dosec BP 8M, BP 12M, BP 6M, BP 8W, BP 12W, BP 6W,
// BP 8F, BP 12F, BP 6F, Norm_BP 6M
// Get all of the numeric continuous column names
col_Names = dt << get column names( string, continuous );
// Get Column Names returns a JMP List of column names
// of the columns that have a Modeling Type of Continuous
// {"BP 8M", "BP 12M", "BP 6M", "BP 8W", "BP 12W", "BP 6W",
// "BP 8F", "BP 12F", "BP 6F"}
// Note that the first 2 column in the data table, Subject and Dose
// are not in the list
// Note: Specifying
// Column( 1 )
// references the 1st column in the data table, which is Subject
// Specifying
// Column( col_Names[1] )
// references the 1st column in the col_Names List, which is BP 8M
// Method 1
// Create the new column. Set Each Value loops through each
// row in the data table and applies the specified formula
// which is to subtract the value in the 1st column in the
// col_Names list from the value in the 3rd column in the
// col_Names list
dt << New Column( "Norm_" || col_names[3],
numeric,
continuous,
Format( "Fixed Dec", 3, 2 ),
set each value( As Column( col_Names[3] ) - As Column( col_Names[1] ) )
);
// Method 2
// Perform the same subtraction, however do it by pulling all of the
// values from each of the 2 target columns into 2 matrices and then
// use matrix math to do the subtraction into an additional matrix
// and then take those values and put them into the new column
// Create the new column with no values
dt << New Column( "Norm2_" || col_names[3],
numeric,
continuous,
Format( "Fixed Dec", 3, 2 )
);
// Pull the data from the 2 columns in the data table
matCola = column( col_Names[1]) << get values;
matColb = column( col_Names[3]) << get values;
// Subtract the values in matCola from matColb
matResults = matColb - matCola;
// Put the results into the new column
column( "Norm2_" || col_names[3] ) << set values( matResults);
Jim