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 );
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:
CharSet("option")
// "Best Guess", "utf-8", "utf-16", "us-ascii", "windows-1252", "x-max-roman", "x-mac-japanese", "shift-jis", "euc-jp", "utf-16be", "gb2312"
Number of Columns(Number)
Columns(colName=colType(colWidth),... )
// colType is Character|Numeric
// colWidth is an integer specifying the width of the column
Treat Empty Columns as Numeric(Boolean)
Scan Whole File(Boolean)
End Of Field(Tab|Space|Comma|Semicolon|Other|None)
EOF Other("char")
End Of Line(CRLF|CR|LF|Semicolon|Other)
EOL Other("Char")
Strip Quotes|Strip Enclosing Quotes(Boolean)
Labels | Table Contains Column Headers(Boolean)
Year Rule | Two digit year rule ("Decade Start")
Column Names Start | Column Names are on line(Number)
Data Starts | Data Starts on Line(Number)
Lines to Read(Number)
Use Apostrophe as Quotation Mark
CompressNumericColumns(Boolean)
CompressCharacterColumns(Boolean)
CompressAllowListCheck(Boolean)
Open(
"$SAMPLE_IMPORT_DATA/EOF_comma.txt",
End of Field( comma ),
Labels( 0 ),
Columns(
name = Character( 12 ),
age = Numeric( 5 ),
sex = Character( 5 ),
height = Numeric( 3 ),
weight = Numeric( 3 )
)
);
Open(
"$SAMPLE_IMPORT_DATA/EOF_space.txt",
Labels( 0 ),
End of Field( Space )
);
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" );
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:
Columns(
name = Character( 15 ),
sex = Character( 5 ),
age = Numeric( 5 )
);
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(
"$SAMPLE_IMPORT_DATA/Animals_line3.txt",
Columns(
Column( "species", Character, "Nominal" ),
Column( "subject", Numeric, "Continuous", Format( "Best", 10 ) ),
Column( "miles", Numeric, "Continuous", Format( "Best", 10 ) ),
Column( "season", Character, "Nominal" )
),
Column Names Start( 3 )
);
Open(
"$SAMPLE_IMPORT_DATA/Bigclass_L.txt",
Columns(
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 ) )
),
Data Starts( 5 )
);
Open(
"$SAMPLE_IMPORT_DATA/Bigclass_L.txt",
Columns(
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 ) )
),
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.
Preferences(
Import Settings(
End Of Field( Tab, Spaces, Comma )
)
);
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.
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.
Open( "$SAMPLE_IMPORT_DATA/Team Results.xlsx", "Excel Wizard" );
dt = Open(
"C:\Excel Wizard Demo\PotatoProduction.xls",
Worksheets( "Worldprod" ),
Use for all sheets( 1 ),
Concatenate Worksheets( 0 ),
Create Concatenation Column( 0 ),
Worksheet Settings(
1,
Has Column Headers( 1 ),
Number of Rows in Headers( 1 ),
Headers Start on Row( 2 ),
Data Starts on Row( 5 ),
Data Starts on Column( 1 ),
Data Ends on Row( 40 ),
Data Ends on Column( 0 ),
Replicated Spanned Rows( 1 ),
Replicated Spanned Headers( 0 ),
Suppress Hidden Rows( 1 ),
Suppress Hidden Columns( 1 ),
Suppress Empty Columns( 1 ),
Treat as Hierarchy( 0 ),
Multiple Series Stack( 0 ),
Import Cell Colors( 0 ),
Limit Column Detect( 0 ),
Column Separator String( "-" )
)
);
•
|
The Excel Open Method preference applies when you run the Open() expression with no argument and select another open method using the down arrow on the Open button.
|
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.
Open( "C:\My Data\cars.xlsx", Worksheets( "small" ) );
Open( "C:\My Data\cars.xlsx", Worksheets( "3" ) );
Open( "C:\My Data\cars.xlsx", Worksheets( {"small", "medium", "large"} ) );
sasxpt = Open( "$SAMPLE_IMPORT_DATA/carpoll.xpt" );
To convert the labels to column headings, include the Use Labels for Var Names argument.
sasdbf = Open( "$SAMPLE_IMPORT_DATA/Bigclass.sas7bdat", Use Labels for Var Names( 1 ));
.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 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.
Open( "http://company1.com/Repairs.jmp" );
Open( "http://company1.com/My Data.txt", text); // specify text on Macintosh
Open( "http://company1.com", HTML Table( n ) );
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.
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.
Open( "\\Data\Repairs.jmp" );
Open( "\\Data\My Data.txt" );
Open( "filename.h5", {"list_of", "dataset_names"});
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.
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" );
dt = Open( "$SAMPLE_IMPORT_DATA/Parishes.dbf" );
dt << Save( "c:/Parishes-Name.jmp" );
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.
JMP does not support importing password-protected .xlsx files. Import password-protected Excel 2007 .xls files by including the Password argument.
Open( "Housing.xls", Password( "helloworld" ) );
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 for more information.
JMP also converts DataBase Files (.dbf) files to data table format.
sasdbf = Open( "$SAMPLE_IMPORT_DATA/Bigclass.dbf",
Use Labels for Var Names( 1 )
);