14.03.2014 Views

Scripting Guide - SAS

Scripting Guide - SAS

Scripting Guide - SAS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 9 Data Tables 235<br />

Data Table Basics<br />

Data Table Basics<br />

JSL has full access to the values and properties of a data table. This section examines how to open and close<br />

data tables, view their properties, and interact with their data.<br />

Once you have a data table open, you accomplish most other data tasks by sending messages to a reference<br />

to the data table object. Objects acting on messages is a common theme in this book. As soon as you see<br />

how to create or open a data table object, step back and look at how objects and messages work.<br />

Getting a Data Table Object<br />

Any of the following methods of beginning to work with a data table produces a data table object.<br />

Opening a Data Table<br />

Opening a data table returns a reference to the data table. Usually, you assign the reference to a variable for<br />

later use. The usual argument for Open is a path (either relative or absolute) to the data table. For<br />

information about using POSIX filenames and the built-in path variables, see “Path Variables” on page 105<br />

in the “Types of Data” chapter.<br />

Open("$SAMPLE_DATA/big class.jmp"); // just open the data table<br />

dt=Open("$SAMPLE_DATA/big class.jmp"); // open and assign a reference<br />

The path can be a literal path (absolute or relative) in quotation marks or an expression yielding a<br />

pathname. Relative paths are interpreted relative to the location of the .JSL file (if the script has been saved)<br />

or the JMP application (for an unsaved script); use ../ to move up one folder level. Example scripts<br />

typically use a relative path to open files from the installed Sample Data folder. You can also use the Set<br />

Current Directory command.<br />

If no arguments are given, Open presents a window prompting the user to navigate to a file.<br />

If a data table with that path is already open, then JMP does not read it again but instead brings that<br />

window in the front. If you have made changes, then the table is not the same as the one on disk that you<br />

might expect. Since JMP always keeps the whole table in memory, opening is equivalent to reading the<br />

whole file.<br />

Test for an Open Data Table<br />

In a script that depends on an opened data table, test to see whether the table is open using Is Empty() or<br />

Is Scriptable(). In the following example, the script performs a Bivariate analysis on Big Class.jmp<br />

and then closes the data table. Before proceeding to the Oneway analysis later in the script, If<br />

Scriptable() tests for the open data table. If 0 is returned, the table opens, and the script continues.<br />

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );<br />

obj = Bivariate( Y( :height ), X( :age ), Fit Line );<br />

Close( dt );<br />

...<br />

If(<br />

Is Scriptable ( dt ), 0,

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!