该帮助的版本不再更新,请参见https://www.jmp.com/support/help/zh-cn/15.2 获取最新的版本.


Open( "$SAMPLE_IMPORT_DATA/Bigclass.xlsx" ); // Microsoft Excel file
Open( "$SAMPLE_IMPORT_DATA/Bigclass.txt" ); // text file
Open( "$SAMPLE_IMPORT_DATA/Carpoll.xpt" ); // SAS transport file
Open( "$SAMPLE_IMPORT_DATA/Bigclass.txt", text );
Additional supported formats include .csv, .jsl, .dat, .tsv, and .jrn.
The following Open() options are available:
Columns(colName=colType(colWidth),... )
// colType is Character|Numeric
// colWidth is an integer specifying the width of the column
"$SAMPLE_IMPORT_DATA/EOF_comma.txt",
"$SAMPLE_IMPORT_DATA/EOF_space.txt",
"$SAMPLE_IMPORT_DATA/EOF_space.txt",
To set the import options interactively, include the Text Wizard argument. A preview of the text file opens in the text import window.
Open( "$SAMPLE_IMPORT_DATA/EOF_space.txt", "Text Wizard" );
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:
John Doe is interpreted as two separate strings (John and Doe).
"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.
"$SAMPLE_IMPORT_DATA/Animals_line3.txt",
Column( "species", Character, "Nominal" ),
Column( "subject", Numeric, "Continuous", Format( "Best", 10 ) ),
Column( "miles", Numeric, "Continuous", Format( "Best", 10 ) ),
Column( "season", Character, "Nominal" )
"$SAMPLE_IMPORT_DATA/Bigclass_L.txt",
Column( "name", Character, "Nominal" ),
Column( "age", Numeric, "Continuous", Format( "Best", 10 ) ),
Column( "sex", Character, "Nominal" ),
Column( "height", Numeric, "Continuous", Format( "Best", 10 ) ),
Column( "weight", Numeric, "Continuous", Format( "Best", 10 ) )
"$SAMPLE_IMPORT_DATA/Bigclass_L.txt",
Column( "name", Character, "Nominal"),
Column( "age", Numeric, "Continuous", Format( "Best", 10 ) ),
Column( "sex", Character, "Nominal" ),
Column( "height", Numeric, "Continuous", Format( "Best", 10 ) ),
Column( "weight", Numeric, "Continuous", Format( "Best", 10 ) )
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.
注意:See Create Excel Workbooks for information about exporting data tables to an Excel workbook.
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:
Path = Convert File Path( "$SAMPLE_IMPORT_DATA/Team Results.xlsx", absolute );
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:
Path = Convert File Path( "$SAMPLE_IMPORT_DATA/Team Results.xlsx", absolute );
New Window( "button", Button Box( "Open", dt = Open( Path ) ) );
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.
Path = Convert File Path( "$SAMPLE_IMPORT_DATA/Team Results.xlsx", absolute );
New Window( "button", Button Box( "Open", dt = Open( Path, Use for all sheets(1) ) ) );
Preference(Excel Open Method( "Open All Sheets" ));
Path = Convert File Path( "$SAMPLE_IMPORT_DATA/Team Results.xlsx", absolute );
New Window( "button", Button Box( "Open", dt = Open( Path ) ) );
dt = Open( "$SAMPLE_IMPORT_DATA/Team Results.xlsx", "Excel Wizard" );
dt = Open(
"$SAMPLE_IMPORT_DATA/Bigclass.xls",
Worksheets( "Bigclass" ),
1,
), "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.
sasxpt = Open( "$SAMPLE_IMPORT_DATA/carpoll.xpt" );
sasdbf = Open( "$SAMPLE_IMPORT_DATA/Bigclass.sas7bdat", Use Labels for Var Names( 1 ));
.xpt and .stx file formats are also supported.
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.
dt = New Table( "test", New Column( "Image", Expression ) );
dt << Add Rows( 1 );
dt:Image = New Image( Open( "http://www.jmp.com/support/help/14/images/MosaicPlot.png" ) );
dt << Add Rows( 1 );
dt:Image = New Image( Open( "http://www.jmp.com/support/help/14/images/tTest_NoLoc.png" ) );
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.
path = "$SAMPLE_IMAGES/"; // images are in this directory
{dtx} = Multiple File Import(
<<Set Folder( path ),
<<Set Name Filter( "*.jpg; " ),
<<Set Name Enable( 1 ), // enable the ability to filter by name,
// in this example, files with the .jpg extension
<<Set Add File Name Column( 1 ), // must be included but can be hidden
<<Set Add File Size Column( 1 ) // for Show Sizes at end
) << Import Data;
dtx:FileName << Hide; // hide the column that contains the image file name.
// The column is required for the image links to work, but you don’t need
For Each Row( // recreate each image to minimize size of data table
x = Eval( dtx:Picture );
x << Scale( .1 ); // scale the image by 10%
m = x << Get Pixels; // compress the image by recreating it
dtx:Picture = New Image( m );
maxheight = Max( maxheight, (dtx:Picture[] << Get Size)[2] );
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. */
Eval Expr(
dtx:picture << Set Property(
"Event Handler",
Event Handler( // Event Handler column property
Click( JSL Quote( Function( {thisTable, thisColumn, iRow},
Open( Expr( path )||Char( thisTable:FileName[ iRow ] ) ); ); ) ),
Tip( JSL Quote( Function( {thisTable, thisColumn, iRow},"Open " || Char( thisTable:FileName[ iRow ] ) || " in your viewer."; ); ) ),
// tooltip for the Tip event handler is shorter than the the tooltip
// inserted for the Click event handler
Color( JSL Quote( Function( {thisTable, thisColumn, iRow}, 5; );) )
) // color of the link -- blue
dtx << Set Cell Height( maxheight + 2 );
dtx << Save( "$TEMP/Sample Images.jmp" );
Show( File Size( "$TEMP/Sample Images.jmp" ), Col Sum( dtx:FileSize ) );
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\!"}]";
d = JSON To Data Table( js ); // convert JSON to a data table
d << New Data View; // make a view of the data table
图 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.
list_of_associative_arrays = {["key1" => "a", "key2" => "b"], ["key1" => "c",
"key2" => "d"], ["key2" => "f", "key1" => "e", "key3" => "g"]};
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.
The following example imports a .shp file and saves it with the -XY suffix.
dt = Open( "$SAMPLE_IMPORT_DATA/Parishes.shp",
:X << Format( "Longitude DDD", 14, 4 );
:Y << Format( "Latitude DDD", 14, 4 ) );
dt << Save( "c:/Parishes-XY.jmp" );
Save the .dbf file with the -Name suffix.
dt = Open( "$SAMPLE_IMPORT_DATA/Parishes.dbf" );
dt << Save( "c:/Parishes-Name.jmp" );
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.
sasdbf = Open( "$SAMPLE_IMPORT_DATA/Bigclass.dbf",