Open( "$SAMPLE_IMPORT_DATA/Bigclass.txt", text );
For more detailed information about import options, refer to “File Functions” in the JSL Syntax Reference.
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
Open(
Labels( 0 ),
name = Character( 12 ),
age = Numeric( 5 ),
sex = Character( 5 ),
height = Numeric( 3 ),
Open(
Labels( 0 ),
Open(
To set the import options interactively, include the Text Wizard argument. A preview of the text file opens in the text import window.
The following sections describe each argument in more detail. For more detailed information about import options, refer to “File Functions” in 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.
Open(
Open(
Data Starts( 5 )
Lines To Read( 10 )
If you want to set preferences for importing text, it can be helpful to first see a list of all preferences. To do so, use the Show Preferences (All) function.
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 “导入 Microsoft Excel 文件” in the Using JMP book for details about Microsoft Excel support.
•
|
Excel Open Method specifies how a Microsoft 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 Microsoft 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 worksheet 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.
Using the Open() function without additional arguments to open an Excel file has different behaviors depending on the context:
•
|
If the Open() function is a direct part of the script, the Excel files open into data tables using your Excel preferences. The following example opens both worksheets into data tables without using the wizard:
|
dt = Open( Path );
注意:To use the Excel Wizard, you must specify the Excel Wizard option in the argument as in Open( "$SAMPLE_IMPORT_DATA/Team Results.xlsx", "Excel Wizard" );.
•
|
However, if the Open() function is part of a script that is run from clicking a button, the Preview window opens and requires the user to interact with it. Run the following example and click the button to see the Excel Import Wizard:
|
•
|
To prevent the button script from opening the Preview window and importing the Excel file directly, provide additional arguments to the Open() function. Run the example and click the button. Both worksheets are opened into data tables without using the Excel Import Wizard.
|
Preference(Excel Open Method( "Open All Sheets" ));
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.
dt = Open(
Worksheets( "Bigclass" ),
Use for all sheets( 1 ),
Has Column Headers( 1 ),
Data Starts on Row( 2 ),
Data Ends on Row( 0 ),
Data Ends on Column( 0 ),
Treat as Hierarchy( 0 ),
Import Cell Colors( 0 ),
Limit Column Detect( 0 ),
Column Separator String( "-" )
), "Excel Wizard"
Preference( Excel Open Method( "Open All Sheets" ) );
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” on page 716 in the “Extending JMP” chapter 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 attempts to preserve the table header defined in a <th> HTML tag. The table header is converted to column headings in the data table. If the <th> tag is wrong or missing, use ColumnNames(n) to specify the nth row. By default, DataStarts(n) will be the next row, or you can specify the DataStarts row.
You can use Multiple File Import() and an Event Handler script to create a data table of thumbnail images that link to a directory of full-size pictures. This example sets the cell height so that it fits the height of the tallest thumbnail.
{dtx} = Multiple File Import(
<<Set Folder( path ),
) << Import Data;
maxheight = 0;
For Each Row( // recreate each image to minimize size of data table
x = Eval( dtx:Picture );
dtx:Picture = New Image( m );
Eval( /* insert the value in the path variable into the Click handler. The path variable won’t be available later, but the path value is needed to concatenate with the file name column’s value to build a link to the image on the computer. */
dtx:picture << Set Property(
Open( Expr( path )||Char( thisTable:FileName[ iRow ] ) ); ); ) ),
Tip( JSL Quote( Function( {thisTable, thisColumn, iRow},"Open " || Char( thisTable:FileName[ iRow ] ) || " in your viewer."; ); ) ),
) // color of the link -- blue
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.
Use JSON To Data Table() to convert the JSON into a data table.
js = "[ { \!"key1\!": \!"a\!", \!"key2\!": \!"b\!"}, {\!"key1\!": \!"c\!", \!"key2\!": \!"d\!" }, {\!"key2\!": \!"f\!", \!"key1\!":\!"e\!", \!"key3\!": \!"g\!"}]";
图 9.1 Imported JSON Data
You can also use JSON To List() to convert a string containing JSON into a list.
list = JSON To List(
"[ { \!"name\!": \!"KATIE\!", \!"age\!": 12, \!"sex\!": \!"F\!", \!"height\!": 59, \!"weight\!": 95 }, { \!"name\!": \!"LOUISE\!", \!"age\!": 12, \!"sex\!": \!"F\!", \!"height\!": 61, \!"weight\!": 123 }, { \!"name\!": \!"JANE\!", \!"age\!": 12, \!"sex\!": \!"F\!", \!"height\!": 55, \!"weight\!": 74 } ]"
Show( list );
As JSON Expr() converts an associative array to a JSON string. You can then export the data into a JSON document.
jx = As JSON Expr( list_of_associative_arrays );
注意:To import the data table as invisible, include the argument Invisible(1) in JSON To Data Table() and omit New Data View.
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 “地图角色” in the Essential Graphing book.
Open Database() opens a database using Open Database Connectivity (ODBC) and extracts data into a JMP data table. See the “Database Access” on page 711 in the “Extending JMP” chapter for more information.
JMP also converts DataBase Files (.dbf) files to data table format.