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 Import Microsoft Excel Files 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:
|
Path = Convert File Path( "$SAMPLE_IMPORT_DATA/Team Results.xlsx", absolute );
dt = Open(Path);
•
|
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 ) ) );
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( "-" )
)
);
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 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.
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 Map Role 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 in Extending JMP 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 )
);