Tip: Keep the log window open to see the output of each script that you run. Select View > Log to open the Log window. See Work with the Log.
The typical way to work with values in a data table is to follow these steps:
1. Set up the data table whose values you want to access as the current data table. Or, if you already have a data table reference, you can simply use that reference.
2. Specify the row or rows whose values you want to access and specify the column name that contains the values that you want to access.
The following example opens the Big Class.jmp sample data table (making it the current data table), and then specifies row 2 in the weight column. A value of 123 is returned in the log, which is the weight for Louise in row 2.
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt:weight[2];
123
If the data table that you want to work with is already open, proceed using one of the following examples:
dt = Data Table( "My Table" ); // the open table named My Table
dt = Current Data Table(); // the table in the active window
dt = Data Table( 3 ); // the third open table
Once you have an open data table with a reference, you can send it messages using either the << operator or the Send function. The following example illustrates both methods:
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << Save();
Send( dt, Save() );
Note the following about messages:
• You can send messages to any data table object (a data table, column, row, and so on).
• Messages sent to data table objects always have the same pattern:
Reference << Message( Arguments );
• Usually, creating a reference and sending many messages to the reference is the easiest approach. However, you can also use the direct route instead of using a reference if you have only one message to send. The following example saves the current data table:
Current Data Table() << Save();
• You can stack up a series of messages in one statement. Commands are evaluated from left to right, and each returns a reference to the affected object. The following example creates a new data table called My Table, adds two columns to it, and prompts you to save it:
dt = New Table( "My Table" );
dt << New Column( "Column 1" ) << New Column( "Column 2" ) << Save( "" );
In this example, each message returns a reference to the data table (dt).
• If you specify too few arguments for a message, JMP presents a window to get the necessary information from you. JMP often presents windows when your script is incomplete, a behavior that you can use to your advantage when writing scripts that need to query users for their choices.
• Some messages come in pairs; one to “set” or assign each attribute, and one to “get” or query the current setting of each attribute.
New Table and Open are commands to create objects that do not exist yet. Once created, you send them messages requesting changes. To close such objects, you must close the objects’ container, because the objects cannot delete themselves.
The following example creates a table and assigns the data table reference to the dt variable. New Column messages are sent to the data table reference. To delete one of those columns, the Delete Columns message is sent to the data table reference, not to the column itself.
dt = New Table( "Airline Data" );
dt << New Column( "Date" );
dt << New Column( "Airline" );
dt << Delete Columns( "Date" );
To see all of the messages that can be sent to a data table object, see the Scripting Index:
1. Select Help > Scripting Index.
2. Select All Categories from the list.
3. Select Data Table in the list.
You can also use the Show Properties() command. This is a good approach if you want to print or copy the list of messages. The Show Properties() command lists the messages that you can send to a data table in the Log window. Show Properties() is a command that takes any scriptable object (such as a data table or column) as its argument. To show properties for a data table:
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
Show Properties( dt );
The resulting message list is hierarchical.
[Subtable] refers to a set of JMP menu commands. For example, the Tables subtable represents the JMP Tables menu, and the indented messages in this subtable correspond to commands in the Tables menu. Many messages include a short description.
Messages labeled as [Action] all result in some action being taken. Some messages are available for [Scripting Only]. Some messages take a Boolean argument, labeled as [Boolean].
The platforms in the Analyze and Graph menus appear in the properties list because you can send a platform name as a message to a data table. This launches the platform for the data table through the usual launch window. For more information about writing platform-specific scripts, see Scripting Platforms.
dt << Distribution( Y( height ) );
Note: In addition to data tables, Show Properties also works with platforms and display boxes.
The JMP Scripting Index provides more information about these properties. You can also run and modify sample scripts from the Scripting Index. Select Help > Scripting Index and search for the property in the Objects list.