Subscribe Bookmark
arati_mejdal

Staff

Joined:

May 21, 2014

Scripting Data in JMP

JMP scripting is an important part of the JMP user experience. Anyone can easily create a reusable JMP "program" with JMP Scripting Language (JSL) by running an analysis, selecting the hotspot (red triangle) at the top of the report, and choosing "Script." From there, you can save a script to a data table, a script window, a journal, or a project.


But did you know that you can also write a script that can create or modify a data table? To see a script that creates a data table, follow these steps:


a) Open a data table in JMP.


b) Open a script window (File->New->Script).


c) In the script window, type Current Data Table() << get script; and run this script (Cntl-R or Edit->Run Script).


d) Open the JMP log (View->Log). In the JMP log, the script that recreates the data table is shown.


e) Copy and paste that script where you need it to go.


An example screenshot of what this process produces is shown below.




I tend to do this a lot, especially when I am preparing presentations using custom journals or when I need a starting version of a data table for a more complicated script. The multi-step process is tedious, so naturally, I wondered if I could write a JMP script that would automate that process. It turns out that it was a pretty simple script.


The JSL is below, and the script file is available for download from the JMP File Exchange.


// Save the script to a global variable

tblScript = Current Data Table() << Get Script;

// Create an empty script box object

scrBox = Script Box();

//You want the text version of tblScript, which

// is an expression. Char turns it into text.

//Name Expr returns the unevaluated expression

scrBox << Set Text(

Char(

Name Expr(tblScript)

)

);

//The script displays in a report window (note the icon

//in the upper left), but can be executed like a script.

newScrWind = New Window(

"Script for Current Data Table",

scrBox

);

// resize the window

newScrWind << Size Window(800,600);

// reformat the script

scrBox << Reformat;

2 Comments
Community Member

Harry Tartan wrote:

How can I write a script in JSL to update a data table each time I run the script instead of going back to the server to pull all the data over and over again?

Community Member

Sam Gardner wrote:

Harry,

There are several JSL commands and logic that you can use to update tables. I probably need a little more information on what you specifically want to do. Send me a direct message at my email (Sam.Gardner@JMP.com) address and I will help you learn what you want to do.