Just as you send data table messages to a data table reference, you can send column messages to a reference to a data column object. The Column function returns a data column reference. Its argument is either a name in quotation marks, something that evaluates to a name in quotation marks, or a number.
This book uses col to represent data column references. To see the messages that you can send to data column objects, refer to the Scripting Index (Data Tables > Column Scripting). Alternatively, you can use the Show Properties command, as follows:
Sending messages to columns is comparable to sending messages to data tables. Either state the object, a double-angle operator <<, and then the message with its arguments in parentheses, or use the Send() function with the object and then the message. In some cases the messages themselves need no arguments, so the trailing parentheses are optional.
Tip: To delete a column, you must send the message to a data table reference, because objects cannot delete themselves, only their containers can delete them.
The log returns the formatted value for x, which is twelve, and the actual data value for y, which is 12.
To add a new column to a data table, send a New Column message to a data table reference. The first argument, the column’s name, is required. Either enclose the name in quotation marks or specify an expression evaluating to the name.
To fill the column with data, use Values or its equivalent, Set Values. Include the value for each cell in a list.
The column can also be filled with numeric values. The following example adds a new column called Row Number to the current data table. The function N Row returns the number of rows in the table, and numeric values populate all of the rows in the column, beginning with 1.
New Column can also be used as a built-in function, in other words, without the << (Send) command applied to the data table reference. When used in this way, the column is added to the current data table.
The Add Multiple Columns message creates several columns at once. Arguments include the column name prefix, the number of columns, where to insert them (Before First, After Last, or After(col)), and the data type (Numeric, Row State, or Character(width)). An additional argument, field width, is optional for a numeric column.
You can group columns by sending the data table the Group Columns message, which takes a list of columns to group as an argument. For example, the following code opens the Big Class.jmp sample data table and groups the age and sex columns.
You can also send a column name followed by the number of columns to include in the group. The group includes the first column named and the n-1 columns that follow it. This line is equivalent to the line above, which groups age and sex:
To ungroup grouped columns, use the Ungroup Columns message, which takes a list of columns in a group as an argument. For example, the following line ungroups the two columns grouped in the previous example.
You cannot create more than one group in a single message (for example, by giving the Group Columns message two lists of columns). Instead, you must send the data table two separate Group Columns messages.
The Ungroup Columns message takes a list of columns to ungroup, not the name of a group of columns. You can remove a partial list of columns from a group. For example, this line creates a group of four columns:
Notice that the grouped columns are now height and weight, but the group name still contains age. Once a group is created, its name does not change, even if you remove the first column that was originally grouped.
To get column groups or names, use Get Column Group or Get Column Groups Names. The first part of this example creates two sets of grouped columns as shown in the previous section. Get Column Group() returns the column names in the specific group. Get Column Groups Names() returns the names of the column groups.
The following example groups columns X and Y and groups columns Ozone through Lead, and then selects those columns in the data table:
To select a column, use the Set Selected message.
For example, to select all continuous variables in the Big Class.jmp sample data table, use the following script:
To actually select the columns before getting the columns, send the Set Selected() message to a column. For more information, see Column Attributes.
dt << Go To (column name | column number);
To minimize the size of a large data table, use the Compress Selected Columns message. Each column is compressed into the most compact form.
dt << Compress Selected Columns( {column name, column name} );
For example, compress the age, sex, height, and weight columns in Big Class.jmp as follows:
To delete columns, send a Delete Columns message and specify which column or columns to delete. To delete more than one column, list the columns as multiple arguments or as a list. The following examples use the Big Class.jmp sample data table:
Without an argument, Delete Columns deletes columns that were previously selected. See Column Attributes for more information.
Column Name(n) returns the name of the n th column. The examples in this section use the Big Class.jmp sample data table.
where the optional argument controls the output of the Get Column Names function, as follows:
Specify Numeric, Character, or Row State to include only those column data types.
Specify "Continuous", "Ordinal", or "Nominal" to include only those modeling types.
Specify String to return a list of strings rather than column names.
For example, if you want to get numeric and continuous columns in the Big Class.jmp sample data table, proceed as follows:
In the following examples, the name column is unhidden, unexcluded, labeled, and locked from horizontal scrolling.
Note: All the messages to set various arguments (for example, Set Name, Set Values, Set Formula) start with Set. The word Set is optional for all messages except Set Name (recall that Name is already used for something else, the command that lets you use unusual characters in a name). Use whichever form you prefer or find easier to remember. The corresponding messages to retrieve the current value of an argument (for example, Get Formula) are the same, except that they start with Get instead of Set, and the word Get is not optional.
To deselect all selected columns, send a Clear Column Selection message to the data table object.
Set Name lets you name or rename a column, and Get Name returns the name for a column. The following example uses the Big Class.jmp sample data table, and changes column 2 (age) to ratio. It then returns the current column name to the log.
Similarly, Set Values sets values for a column. If the variable is character, the argument should be a list. If the variable is numeric, the argument should be a matrix (vector). If the number of values is greater than the current number of rows, the necessary rows are added to the data table. Get Values returns the values in list or matrix form. Get As Matrix is similar to Get Values but returns values in the numeric columns.
You can specify value labels in any one of the following three ways. Using the Big Class.jmp sample data table, assume that M maps to Male, and F maps to Female.
You can activate value labels by sending Use Value Labels as a message to the column.
The Format message controls numeric and date/time formatting. The first argument is a quoted string from the list of format choices shown in the Column Info window. Subsequent arguments depend on the format choice. You can also set the field width by itself.
For date formats, the Format message sets how dates appear in a data table column. To set the format that you use for entering data, or for displaying the current cell when you have it selected for entry or editing, use the Input Format message.
Note: Do not confuse the Format message for columns with the Format function for converting numeric values to strings according to the format specified (typically used for date/time notation as described in Date-Time Functions and Formats in Types of Data). Sending a message to an object has a very different effect from using a function that might happen to have the same name.
To force a single column to evaluate, you can send an Eval Formula command to the column. You can do this inside the command to create the column, right after the Formula clause:
where Formula is an alias for Set Formula.
However, it is best to wait until you are finished adding a set of formulas, and then use the command Run Formulas to evaluate all of the formulas in their proper order, as follows:
The Run Formulas command is preferable to the Eval Formula command, because while it is evaluating the formulas, Eval Formula does not suppress the background task from evaluating them again. The formula dependency system background task takes great care to evaluate the formulas in the right order, and RunFormulas simply calls this task until all the formulas are finished evaluating.
If you use random numbers and use the Random Reset(seed) feature to make a replicable sequence, then you have another reason to use Run Formulas, in order to avoid a second evaluation in the background.
a x b
a x <b
a < x b
a < x < b
All of the operators can be preceded by Not and one of them can be missing. The following example specifies that the values in the age column should be greater than or equal to 12:
To retrieve the list or range check assigned to a column, send a Get List Check or Get Range Check message to the column:
For example, if you sent a Get Range Check for the age column in the example above (where values should be greater than zero and less than 120), the following output appears:
Note that you can also use Set Property, Get Property, and Delete Property to set, retrieve, and remove list checks and range checks. See Column Properties for more information.
Get Script returns a script to create the column.
To preselect a role on a column, use the Preselect Roles message. Choices include No Role, X, Y, Weight, and Freq. The Get Role message returns the current setting.
To lock or unlock a column, use Lock or Set Lock with a Boolean argument. Get Lock returns the current setting.
Tip: JSL choices for properties are the same as those in the Column Properties menu in the Column Info window. The arguments for each property correspond to the settings in the Column Info window. An easy way to learn the syntax is to establish the property that you want in the Column Info window first, and then use Get Property to view the JSL.
The name of the property in question is always the first argument for Set Property, and what is expected for subsequent arguments depends on which property you set:
Get Property and Delete Property always take a single argument, which is the name of the property.
Get Property returns the property’s settings. Delete Property completely removes the property from the column.
If you want to set several properties, you need to send several separate Set Property messages. You can stack several messages in a single JSL statement if you want.
To get a property’s value, send a Get Property message whose argument is the name of the property that you want:
The same syntax works for Set Scroll Lock Columns, and Scroll Lock.
Properties for Data Table Columns shows examples for setting and getting column properties. See The Column Info Window chapter in Using JMP for more information on each property.
Choices for Goal are Maximize, Match Target, Minimize, None. Other arguments take numeric value and desirability arguments.
Choices for role are Continuous, Discrete Numeric, Categorical, Blocking, Covariate, Mixture, Constant, Uncontrolled, Random Block, Signal, and Noise.
Provided for custom uses. Corresponds to Column Properties > Other in the Column Info window.