Chapter 1: Make JMP Work for You

Overview

Capturing Scripts from Your Analyses

Saving Scripts to a Data Table

Saving Scripts to a Script Window

Saving Scripts to the Clipboard

Capturing Scripts from Imported Data

Capturing Scripts from Data Manipulations

Creating a Combined Script

Importing the Text Data

Creating a Distribution Analysis

Executing a Script

Checking the Log

Saving a Script

Summary

Overview

Have you ever worried that you will have to write pages and pages of code, and won’t know where to start? There’s no need to fret, because JMP, the best scripter of all, can write the scripts for you. We’re going to show you how. 

In this chapter, you will learn about:

        capturing scripts from your analyses

        using scripts from imported data and data manipulations

        creating a combined script composed of two separate captured scripts

Capturing Scripts from Your Analyses

You just created a report that impresses your manager. She likes it so much that she wants the report weekly. So, what to do?

Do not panic. Instead, save the scripts and execute them next week to create your report. 

In your report, you might have noticed the red triangle icons, clicked on a few of the icons, and used some of the options in the drop-down menus to modify or customize your analysis. See Figure 1.1 for an example.

Figure 1.1  Bivariate Menu

Figure 1.1 Bivariate Menu  

Did you know that you can capture a script of your analysis, plus many of the post-analysis changes you made? While JMP does not record every step you perform interactively, you can reproduce your results with scripting.

In Figure 1.2, notice the last item on the menu is Save Script.  Selecting it opens a sub-menu that itemizes choices for saving the analysis script to regenerate the report, including most options. 

Scripts that are generated by JMP can be captured in a variety of ways using selections in the Save Script menu.

Figure 1.2  Save Script Menu

Figure 1.2 Save Script Menu

Let’s take a look at three of these options.

Saving Scripts to a Data Table

Keeping a script with its associated data is a good idea. The Save Script To Data Table option stores the script as a property of the data table known as a table script. As a table script, it stays with the table until you delete it. You can update or add data to the table, execute the script, and see the results. And when you save the table, you also save the script. So when you give the data table to a colleague, she can open the table, execute the scripts with the data you intended, and view your reports.

After selecting Save Script To Data Table, you are prompted to provide a name for the table script or accept the default.  In this dialog, you can also choose to replace an existing table script that has the same name or simply to append a suffix to ensure a unique name is assigned.

Figure 1.3  Table Script Naming

Figure 1.3 Table Script Naming 

A green triangle icon, sometimes referred to as a play button, appears in the table panel beside the new table script. Clicking the green triangle icon runs the script. Right-clicking the table script name opens a menu with several items: Run Script, Edit, Delete, Group Scripts/Ungroup Scripts, Copy, Debug Script, and Paste.   

Figure 1.4  Table Script Options

Figure 1.4 Table Script Options

Choosing Run Script executes the script.  This is the same action as clicking the green triangle icon.

Selecting Edit opens a window where you can view and edit the script.

Figure 1.5  Sample Script That Was Saved as a Table Script

Figure 1.5 Sample Script That Was Saved as a Table Script

Selecting Delete removes all selected table scripts from the data table.

The Group Scripts option provides the ability to group selected table scripts.  This enables you to organize your table scripts in a manner that makes sense for the data or even your analysis process.

For example, suppose you wanted to arrange the first three table scripts in the Big Class data table as a group called Basic Analyses.  You would begin by selecting the three table scripts, right-clicking any one of them, and selecting Group Scripts.

Figure 1.6  Group Scripts

Figure 1.6 Group Scripts

The default name is based upon the name of the first table script and also provides an indication of the number of table scripts included in the group.  Simply click the group name once to rename it to something more meaningful.  Right-clicking the group and selecting Run Script runs each table script in the order in which they appear in the group.

Figure 1.7  Renamed and Run Group Script

Figure 1.7 Renamed and Run Group Script

The Copy option seems obvious but can be a bit deceiving.  In fact, it does more than store the selected table script to your clipboard.  The script that is copied includes the entire data table message used to add a new table script, which makes for easy pasting of the table script into a different data table. 

To see what we mean, suppose you saved a script in your data table named Distribution of height.  Selecting Copy would place the following code on your clipboard:

Add Properties to Table(
   {New Script(
          "Distribution of height",
          Distribution( Continuous Distribution( Column( :height ) ) )
   )}
)

If you only wanted the contents of the table script, you have the following options:

1.       Paste the preceding code into your main script and delete the unwanted options.

2.       Select Edit, and then select and copy the desired section of the script.

Selecting the Debug Script option opens the JSL Debugger. The details and usage of the JSL Debugger are discussed in chapter 5.

Finally, the Paste option is another one that seems straight forward but has a little twist.  When you select the Paste option, JMP actually just runs the script that is on your clipboard.

For example, if you had the entire Add Properties to Table() script, as shown above, stored on your clipboard,  the script would be executed and the new table script would appear in the table panel.  

On the other hand, if you only had the Distribution() code on your clipboard, then the Distribution report would appear and no new table script would be added to the table panel.

image shown here

Did you know that many of the sample data tables in your JMP installation include scripts that have already been saved? Right-click the green triangle icon to the left of a script that interests you, and then select Edit to display a ready-made script.

Figure 1.8  Table Panel with Saved Scripts

 

Saving Scripts to a Script Window

The Save Script To Script Window option places your script into a window named Script Window. This window is a script editor where you can edit your saved script. If this window is kept open, you can accumulate scripts from additional analyses by issuing the Save Script To Script Window command from those reports. 

It is easy to save your script as a script file from this window. Select File Save As, and then select Save As Type, JMP Scripts (*.jsl)

Figure 1.9  Script Window with Bivariate Script

Figure 1.9 Script Window with Bivariate Script

Saving Scripts to the Clipboard

This is an easy one. The To Clipboard option places the script on the clipboard, and then you can paste the script wherever you need it.

Capturing Scripts from Imported Data

Importing data from various sources can be a tedious, arduous task.  For the data types used most often, you can extract the script from JMP after importing the data using interactive methods. 

The resulting JMP table automatically includes a table script named Source. This table script contains the JSL needed to import the data again using the same settings. 

Figure 1.10 Text Import Table

Figure 1.10 Text Import Table

To see the code that JMP generated to reproduce the import of the data, right-click the green triangle icon next to Source, and select Edit. Notice in the following figure that the code consists of an Open statement with all possible settings needed to import the Excel file.

Figure 1.11  Source Script for Excel Import

Figure 1.11 Source Script for Excel Import

Using File Open, you can choose to open a variety of file types.  Of the file formats supported by default, Source table scripts are included when any of the following data files are imported:

        Excel files

        text files

        SAS data sets

A new feature for JMP 14 is the ability to import multiple text data files.  By accessing this feature from the File Import Multiple Files menu, you can choose to import text files stored in a variety of formats from a single directory. This feature allows you the flexibility to specify all the files in the directory or to narrow the list by specifying the file types, characters in the name, range of file sizes, or a range of file modified dates.  For unstructured file types, there are options for how the data should be imported.  There are also options to stack files that have a similar format into a single data table or to open each file in separate data tables.  You can also add columns to the resulting data table that identify the name, size, and modified date of the source file. 

This handy new feature is already popular with users.  Just like other imported data, the resulting JMP data tables will have a Source table script containing the code to perform the import with the same settings again.  A second table script called Files contains a list of files that were imported.

In the File Database menu, there are two options to import data from a database.  The Query Builder enables you to build complex SQL queries without having to write the SQL statements.  Upon running the query, the resulting JMP data table contains a Source table script.  Passwords are masked by the code %_PWD_%.

The Open Table option is the traditional method for connecting to an ODBC data source, which is frequently used to import data using less complicated SQL statements.  With default preference settings, the resulting table contains a Source table script with the password clearly visible.  If you do not see any table scripts in the resulting table, select File Preferences and deselect the check box beside ODBC Hide Connection String found in the Tables preference group. With this preference turned off, the Source table script will appear the next time you use the Open Table method to import data from an ODBC database.

Using File SAS, you can connect to SAS installed on your local machine or SAS that is running on a server.  The Browse Data option enables you to navigate your libraries to select the data to be imported.  The SAS Query Builder is similar to the SQL Query Builder in appearance and functionality, except it is specifically used for importing SAS data.  With either of these methods a Source table script is included in the resulting JMP data table.

Finally, the File Internet Open menu enables you to import data from a URL.  When you use the Open as Data option, the data selected from the URL is imported into a new JMP data table.  The resulting table contains a Source table script.

Capturing Scripts from Data Manipulations

Just as you captured scripts from importing data, you can perform some data manipulation tasks through the interactive menus, and JMP will save the script for you. 

Almost every option on the Tables menu saves a Source table script. 

Figure 1.12 Tables Menu

Figure 1.12 Tables Menu

The exceptions are Anonymize and any of the other options that enable you to replace or update the existing table. 

For example, suppose you wanted to sort the Fitness sample data table by name.  You would select Tables Sort and cast Name as the By column. 

Figure 1.13  Sort by Name

Figure 1.13 Sort by Name

If you click OK at this point, a new data table is generated with a Source table script that provides you with the code to sort the original data table by the Name column.  However, if you select the Replace table option, then the data is sorted in place, and no Source table script is added to the original table.  If you do want the table replaced, copy the Source script and add a comma plus the option Replace Table, as shown below:

Data Table( "Fitness" ) << Sort( 
   By( :Name ), 
   Order( Ascending ), 
   Replace Table 
)

Compare Data Tables is special in that it does not generate a new data table unless requested.  In some ways, it is more like an analysis.  There is a Save Script red triangle option in the results window.  If you select Save Differences Summary from the red triangle, a new data table appears with a Source table script that contains the JSL script to re-create the Compare Data Tables report.

Another type of data manipulation where you can extract the script is Cols Recode

Figure 1.14  Recode Menu with Column Selected

Figure 1.14 Recode Menu with Column Selected

The key is to extract the script using the red triangle before you dismiss the window.  In Figure 1.15, the script was saved for recoding the Event column in place by selecting Script Save to Script Window from the red triangle.  You can also save the script for recoding to a new column or a new formula column.

Figure 1.15  Save Recode Script to Script Window

Figure 1.15 Save Recode Script to Script Window

Figure 1.16  Saved Script for Recode

Figure 1.16 Saved Script for Recode

The data filter for the data table, Rows Data Filter, gives users the ability to create complex data subsets, as well as options to hide and exclude portions of data from plots and analyses.  After you have done all that hard work to make the perfect filtering setup for your table, you can easily save a script of the data filter for the next time. Click the red triangle icon next to Data Filter and select Save Script To Data Table, where it will be conveniently stored with the table.   Or you can select one of the other options from the Save Script submenu, such as the To Script Window, to incorporate the data filter script into a custom script of your design.

Figure 1.17  Data Filter Save Script Menu

Figure 1.17 Data Filter Save Script Menu

The Data Filter option also enables you to capture the selection criteria by selecting Save Where Clause from the red triangle menu.  The result is a Select Where() expression that you could use in a main script.  However, unlike other scripts that we have shown you, this code cannot be run as it is.  We will demonstrate Select Where() in further detail in chapter 7.  For now, we just want to point out that you can save the selection criteria.

Another useful feature is the Copy Table Script option, located in the red triangle menu to the left of the table name: 

Figure 1.18  Copy Table Script Menu Item

Figure 1.18 Copy Table Script Menu Item

By selecting this option, you can create a script that makes an exact duplicate of your data table.  Keep in mind that the JMP application does not record all of your changes and actions made to the data table. Rather, the Copy Table Script option captures the current state of the data table in a script when selected. 

Why use this option?  Capturing a script of your table is a great method for showing you how features are scripted in your table.  Want an easy way to capture a script of those formulas or column properties you painstakingly created interactively? Use Copy Table Script and paste the captured script into a Script window, where you can locate and extract those portions of the script for use elsewhere.  

image shown here

Keep in mind that Copy Table Script places all of the values in each row and column on your clipboard.  If your table is rather large, copying and pasting the script will be slower than for smaller data tables.

Figure 1.19  Table Script

Figure 1.19 Table Script

Creating a Combined Script

Now that you’ve seen how easy it is to capture scripts, we are going to show you something a little more interesting. Remember that your manager wants the report generated each week? We will show you how easy it is to create a script that imports the data and makes the report.

In this sample, we put together a script that does the following:

        imports some text data

        creates a Distribution analysis

Importing the Text Data

Let’s begin by importing the Bigclass_L.txt file. 

1.       Select File Open. You can find this file in the Sample Import Data folder. For a typical JMP or JMP Pro 14 Windows installation, you would find the file in this directory:

 

C:Program FilesSASJMP14SamplesImport Data

C:Program FilesSASJMPPRO14SamplesImport Data

 

Bigclass_L.txt is a tab-delimited file. If you use the Data, using Text Import preferences option as shown in Figure 1.20, tab must be specified as an End of Field option in your text import preferences (this is a default setting).

Figure 1.20  Open Text File for Windows

Figure 1.20 Open Text File for Windows

2.       After the data file is imported into JMP, right-click the green triangle icon beside Source and select Edit.

3.       In the resulting window, select the entire script and copy it by right-clicking the selected text and selecting Copy.

Figure 1.21  Copy of Source Script

Figure 1.21 Copy of Source Script

4.       Click OK to dismiss the Source Table Script window. 

5.       From the File menu, select New Script.

6.       Paste the script by clicking the Edit menu and selecting Paste

7.       Add a semicolon after the last closing parenthesis, because you will be adding more code.   

image shown here

The semicolon, known as the Glue operator, is necessary in this case because it tells JMP to expect further JSL statements. Additional details about the Glue operator can be found in chapter 4.

Figure 1.22 Paste of Import Code

Figure 1.22 Paste of Import Code

8.       Press the Enter key a couple of times to move the cursor down a few lines.

Creating a Distribution Analysis

So far, we have pasted the script to import a text file into a Script window. Now, we will create a Distribution analysis and save its script. 

1.       From the Analyze menu, select Distribution

2.       Cast age in the Y, Columns role and click OK.

Figure 1.23  Distribution Launch Window 

Figure 1.23 Distribution Launch Window

3.       In the Distribution analysis window, capture the script by clicking the uppermost red triangle and selecting Save Script To Clipboard.

Figure 1.24  Copy Script to Clipboard

Figure 1.24 Copy Script to Clipboard

This action saves the Distribution script onto the clipboard. 

Now return to the Script window that contains the text import script, and place the cursor in the space below the semicolon, near the bottom of the window.

Figure 1.25  Placing the Cursor

Figure 1.25 Placing the Cursor

4.       To paste the Distribution script from the clipboard into the Script window, select Edit Paste. 

5.       Add a semicolon after the last closing parenthesis in case you later decide to add code and because this is a good programming practice. 

Figure 1.26  Script Window with Distribution Script Pasted

Figure 1.26 Script Window with Distribution Script Pasted

6.       Close the Distribution analysis window that we created interactively, and then close the data table, Bigclass_L, leaving only the Script window open.

7.       Finally, let’s look at the different methods we can use to initiate script execution and then run the script to verify that it produces the expected results.

Executing a Script

There are several ways to execute a JSL script:

        From the Edit menu, select Run Script.

        Click the Run Script button on the toolbar. image shown here

        Right-click anywhere in the Script Editor window, and select Run Script from the pop-up menu.

        Use the keyboard shortcut for this same action:  CTRL+R.

        Double-click a JSL file from a file browser.

image shown here

To execute or run a script means the same thing, and we might use the terms interchangeably throughout this book.

For this case, we will use the first method. From the Edit menu, select Run Script.

Now you will see that the text was imported into a data table, and the Distribution analysis was created from that data.

Figure 1.27  Results of Executing Combined Captured Scripts

Figure 1.27 Results of Executing Combined Captured Scripts

Checking the Log 

The Log window is where the code that you executed is displayed, along with any messages JMP has returned. If you have not already done so, display the Log window by clicking the View menu, and then selecting Log.  

You can either leave the Log window as a separate window, or you can embed it into your Script window. To embed the Log into the Script window, right-click anywhere inside the script, and then select Show Embedded Log.

The Log window is also a Script Editor, which means that you can select code and execute it directly from within the log.

Figure 1.28  Log Window Showing Code

Figure 1.28 Log Window Showing Code

The Distribution[ ] shown at the bottom of the log represents the Distribution object that is returned by the Distribution platform.  This is simply the return value from running the Distribution() script.

Saving a Script

Let’s save the script, because we will be coming back to it later. 

1.       Bring the script that we created to the forefront of the JMP application by selecting
Window Script

2.       On the File menu, select Save As

3.       Navigate to a convenient, yet memorable, location, and name the script Sample1.JSL.

4.       Click the Save button.

Figure 1.29  Save Sample1.JSL

Figure 1.25 Save Sample1.JSL 

You are finished! You have put together an entire script that will do the following:

        import text data

        create a Distribution report

Summary

Now you’ve learned how JMP can work for you by extracting scripts of your reports, your imported data, and some data manipulations. 

What’s next? It’s time to roll up your sleeves, because in the next chapter we will show you how to stitch together multiple scripts using the Script Editor.

 

 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset