Use the Open() function to open a data table.
The path to the data table can be a quoted literal path (absolute or relative) or an unquoted expression that yields a pathname. Relative paths are interpreted relative to the location of the .jsl file (for a saved script). For unsaved scripts, the path is relative to your primary partition (Windows) or your <username>/Documents folder (Macintosh).
JMP provides shortcuts (path variables) to directories or files. Instead of entering the entire path to the directory or file, you include a path variable in the Open() expression. For example, JMP sample scripts typically use the $SAMPLE_DATA path variable to open files in the Samples/Data folder. For details about path variables, see Path Variables in Types of Data.
In a script that depends on an opened data table, you can test to see whether the table is open using Is Empty() or Is Scriptable(). In the following example, the script performs a Bivariate analysis on Big Class.jmp and then closes the data table. Before proceeding to the Oneway analysis later in the script, Is Scriptable() tests for the open data table. If 1 (true) is returned, the table opens, and the script continues.
You can use an If() expression to prompt a user to open a data table, if no open data table is found. And if they do not select a table, the script should end. The following script shows an example:
The user is prompted to open a data table. If the user clicks Cancel instead of opening a data table, an error appears in the log.
To open a data table and show only a specific set of columns, identify those columns in the Open() expression. This is particularly helpful with a large data table in which only a few columns are necessary.
The following sections describe the optional arguments for the New Table() function.
An optional argument that can define the new table. For example, the following script creates a new data table named Little Class. It adds three rows and two named columns as well as entering values for each cell in the table:
Note: On Macintosh, if you do not specify the text file type, the text file opens in the Script Editor.
The Import Settings in the Text Data Files preferences determine how text files are imported. For example, column names begin on line one and data begin on line two by default. To use different settings, specify the import settings as Open() options in your script.
The following Open() options are available:
// colType is Character|Numeric
// colWidth is an integer specifying the width of the column
The following sections describe each argument in more detail. For more detailed information about import options, refer to the JSL Syntax Reference.
Identifies column names, column types, and column widths with a Columns argument as shown in the preceding examples.
If you specify settings for a column other than the first column in the file, you must also specify settings for all the columns that precede it. Suppose that you want to open a text file that has four columns (name, sex, and age, and ID, in that order). age is a numeric column, and the width should be 5. You must also set the name and sex column types and widths, and list them in the same order:
After the data is imported, you use the modeling type for a column. See Set or Get Data and Modeling Types.
•
|
•
|
"John Doe" is interpreted as a single string. Most programs (including JMP) read a quotation mark and ignore other field delimiters until the second quotation occurs.
|
•
|
If you include Strip Quotes(1), "John Doe" is interpreted as John Doe (one string without quotation marks).
|
Use the Other option to use an additional character for the row separator, which you must specify in the EOLOther argument. JMP interprets either this character or the default character as a row separator.
•
|
Use the Other option to use a different character for the field separator, which you must specify in the EOFOther argument.
|
•
|
The Space option uses a single space as a delimiter.
|
•
|
The Spaces option uses two or more spaces.
|
Specifies the character or characters used to separate fields or rows. For example, EOLOther("*") indicates that an asterisk separates rows in the text file.
When you open a Microsoft Excel workbook in JMP, the file is converted to a data table. JMP supports .xls, .xlsm, and .xlsx formats. See the Using JMP book for details about Microsoft Excel support.
•
|
Excel Open Method specifies how an Excel file should be opened by default, when using a non-specific open statement.
|
‒
|
Use Excel Wizard opens the Excel Import Wizard to import the file. This is the default setting.
|
‒
|
Open All Sheets opens all worksheets in the Excel file.
|
‒
|
Select Individual Worksheets prompts users to select one or more worksheets when they open the file.
|
•
|
Use Excel Labels as Headings determines whether text in the first row of the spreadsheet is converted to column headings in the data table.
|
By default, JMP takes the best guess. If names have been defined for all cells in the first row, the text in those cells is converted to column heading. Otherwise, columns are named Column 1, Column 2, and so on.
The Excel Import Wizard shows a preview of the data and lets you modify the settings before importing the data. Specify "Excel Wizard" as the argument.
Suppose that you want to import data from specific worksheets in your workbook. Specify those worksheets using the Worksheets argument. In the following example, the worksheet named small is imported into JMP.
To convert the labels to column headings, include the Use Labels for Var Names argument.
.xpt and .stx file formats are also supported.
On Windows, you can also open SAS data sets from a SAS server. See Connect to a SAS Metadata Server in Extending JMP for details.
In the Open() command, specify the quoted URL to open a file from a website. You can open JMP data tables or other supported file types this way.
n identifies which table you want to import. For example, to import the fourth table on the page, specify HTML Table(4). If you omit the value, only the first table on the page is imported.
JMP can import files stored on a shared computer, such as another computer or a network drive. The file path can be absolute or relative. The following examples show how to open files from a shared computer named Data. If you plan to share the script, it’s safer to use a relative path to the computer, not a path to the mapped drive.
An ESRI shapefile is a geospatial vector data format used to create maps. JMP imports shapefiles as data tables. A .shp shapefile consists of coordinates for each shape. A .dbf shapefile includes values that refer to regions. To create maps in JMP, you modify the structure of the data and save the files with specific suffixes.
Restructuring the data requires several steps, including adding a Map Role column property to names in the -Name.jmp file. For details, see Essential Graphing.
JMP does not support importing password-protected .xlsx files. Import password-protected Excel 2007 .xls files by including the Password argument.
Note: Password-protected Excel version 2010 and 2013 .xlsx files are not supported even if you save the file as .xls.
Open Database() opens a database using Open Database Connectivity (ODBC) and extracts data into a JMP data table. See the Database Access in Extending JMP for more information.
JMP also converts DataBase Files (.dbf) files to data table format.
To switch to another open data table, specify the name of the data table in Current Data Table():
Current Data Table() can also take a scriptable object reference as an argument. The following expression would make the data table in use by the second Bivariate object the current data table:
For more information about using references to analysis platform objects, see Sending Script Commands to a Live Analysis in Scripting Platforms.
Assign a name to a data table by sending it the Set Name message. The argument is a filename in quotation marks, or something that evaluates to a filename.
To retrieve the name, send a Get Name message to the data table:
To save a data table, send a Save message to the data table. Here are some examples:
Note: If you specify the filename with no path and have not set the default directory, the file is saved on your primary partition (Windows) or in your <username>/Documents folder (Macintosh). For details about setting the default directory, see Relative Paths in Types of Data.
On Windows, saving with a .txt extension exports according to the Text Export preferences. On Macintosh, add Text as a second argument to the Save function, as follows:
If you plan to set the name of a data table and later send the Save message, you can just specify the name in a Save message.
To return to the most recently saved data table, send a Revert message to the data table.
dt << Revert();
There are two ways to hide a data table if the user does not need to see the table: by opening it as invisible or private.
An invisible data table is hidden from view but linked to analyses that you run on it. Open a data table as an invisible file as follows:
Here is an example of creating an invisible table, called Abc, that has ten rows. One column is named X.
To find out if an open data table is invisible, pass the Boolean Has Data View message to the data table object. The following expression returns 0 (false) if the data table is invisible:
dt << Has Data View();
After you are finished with an invisible data table, do not forget to close it with the Close() function. Otherwise, the data table remains in memory until you quit JMP.
The Show Window() function shows an invisible data table.
The user has the option of opening the table from the JMP interface. On Windows, an invisible data table appears in the Window List on the Home Window and the Window > Unhide menu. On Macintosh, the data table appears in the JMP Home window and the Window > Hidden menu.
Completely hide the data table from view by including the private argument:
Print a data table by sending it a Print Window message. JMP uses your computer’s default printer settings.
dt << Maximize Display forces the data table to re-measure all of its columns and zoom to the best-sized window.
To close a data table, use a Close command with the data table’s reference as the argument. Data tables with unsaved changes are saved automatically, including any linked tables. Reports and graphs generated from the data tables are also closed.
Tip: Close All() also works with journals and layouts. Specify “Journals” or “Layouts” in the argument.
When using a DataBrowserBox created using New Data Box(), use Set Data Table() and Get Data Table() to set and return a data table.
The following example uses the Big Class.jmp and cities.jmp sample data tables. The sample data tables are opened invisibly. In a new window, a new data box is created containing Big Class.jmp. After waiting 1 second, the data box contents change to display cities.jmp.
If you want to perform an action on all of the data tables that are currently open, use N Table to get a list of references to each one:
openDTs now is a list of references to all open data tables. You can send messages to any one by using openDTs(n). You can use a for loop to send messages to all of the open data tables. This loop adds a new column named My Column to each open data table.
If you just want a list of table names and not references, use the Get Name message:
You can also create a new journal window and immediately add to it within the New Window() command. The following examples create an empty untitled journal and layout:
•
|
Similar to Freeze All but only within areas of a report called pictures.
|
•
|
Similar to Freeze Pictures but only within frame boxes (which are within pictures).
|
•
|
Similar to Freeze Frames but only for the frame boxes that have scripts to draw something on them.
|
Current Journal() returns a reference to the display box at the top of the current journal display window. If no journal is open, one is created. There are no arguments.