Introduction to the JMP Scripting Language
Before launching the course, please download and extract the zip file above (intro-to-jsl-journal.zip) for use with the course activities. This course covers a range of scripting...
Before launching the course, please download and extract the zip file above (intro-to-jsl-journal.zip) for use with the course activities. This course covers a range of scripting...
Another useful data structure is a matrix, which is a rectangular array or table of numeric values or missing values. You can use a matrix to store a single number, a column of numbers, (sometimes called a column vector,) a row of numbers, (or row vector,) or an entire table of numbers. A matrix can be empty -- that is, have no rows or columns. An empty matrix can be useful for collecti...
You can use the Matrix function to create a matrix. And this function takes a list of lists as its argument, where each sub-list specifies a row. You can also use the square brackets operator to create a matrix. When you use this operator, you enter the values directly, without using lists. Instead, you separate the values in different rows with commas, and the values in different colum...
So this demonstration is going to look at some of the basic features of lists and matrices. So I'm going to start with lists. And I'm going to get a new script editor window. So again, the keyboard shortcut is Ctrl+T. And I will resize and rearrange that. Let me go ahead and bring the log in front of the journal. And I'm going to create a variable I'll call my list. And I'll assign that...
So, although your scripts follow a strict syntax, there's no strict style imposed by JMP in the scripting language. Remember that JMP ignores whitespaces and letter case. So, style, then, is important for legibility. Let's take a look at an example. The script shown here follows the syntax rules and will run correctly. But the style -- or lack of style -- make it difficult to read and u...
Scripts are procedural. In other words, JMP evaluates a script beginning with the first line and continuing until the last line. Some scripts require JMP to repeat an action multiple times. But you don't repeat the code for that action in your script for every time you want JMP to perform the action. Instead, you use special iteration functions to repeat that portion of the code. In som...
So, the For function provides the most general form of iteration. This function has four required arguments, and each one is a JSL expression. And as usual, these four arguments are separated by commas. JMP evaluates the first argument to the For function only once. Generally, you use this first argument to initialize a variable that you can use as a counter, or index, in each iteration...
Another way to iterate is with the While function. This function takes only two arguments: the test, and the body. So, if you want to use a counter, index, or flag variable in either argument, you need to initialize those before you call the While function. JMP evaluates the first argument and interprets it as a Boolean result in order to determine if the iteration should continue. If t...
Expressions are an important concept, and an integral part of the JMP scripting language. But what is an expression? Well, it's a section of JSL code that accomplishes a task. JSL expressions hold data, manipulate data, and send commands to objects. An expression can be defined as any combination of variables, constants, and functions or operators that can be evaluated. It might be as s...
So, the Script Editor is a really powerful tool for both reading and writing your scripts. You can also evaluate just one line of code or a selection of code to verify the behavior as you develop your script. And you can hover over a variable name to determine its current contents. You can also use the JMP Log to examine the results of evaluation or any error messages. The Debugger is a...
So this demonstration illustrates how to use the For function for iteration. And so far, we've used the Script Editor with the log to test our scripts and observe the results. But now we want to look at that using the debugger. So I have a script editor window open, and I'm going to start by typing Names Default to Here. And I'll put that Boolean I'm not adding spaces right now. I'm goi...
So, you learned about the For function, which you can use for practically any kind of iteration. There's also a special function for iterating down the rows of the data table, and that's the For Each Row function. This function only requires one argument, which is the body or code that you want JMP to evaluate row-wise. For Each Row iterates down the rows of the data table until it come...
One special case of iteration is the algebraic sum. The Summation function requires three arguments. The first argument is evaluated before the summation begins. It's generally used to initialize a counter or index variable. The second argument specifies a limit for the counter or index. And the third argument is the quantity to be added to the sum. For example, calling the Summation fu...
Another special case of iteration is the algebraic product. The Product function is similar to the Summation function, and also requires three arguments. The first argument is evaluated before the multiplication begins, and is generally used to initialize a counter or index variable. The second argument specifies a limit for the counter or index. And the third argument is the quantity t...
In this demonstration, we'll see how to iterate across rows using the for each row function. So I'm going to get the Big Class data from the script in section And I'm going to write a script that's going to create a new column with the BMI, or Body Mass Index, values. And I'll use the for each row function to populate that. And the body mass index is calculated by multiplying the weight...
Remember, scripts are procedural. JMP begins by evaluating the first line and continues through until it ends with the last line. This kind of evaluation makes sense for the parts of your script that always have to be evaluated. This evaluation is unconditional. But some parts of your script should only be evaluated under specific cases. This evaluation is conditional. And your script h...
The most general way to test conditions is to use the If function. Let's take a look at it in the context of iterating down the rows of a data table to populate a column called "grade" using the For Each Row function. In fact, we'll look at each of the conditional functions in the context of the For Each Row function. Now, the number of arguments for the If function varies, but at least...
So let's look at an example of using the If function. Suppose you have data from a public school in the US with grade levels for each student. Some grade levels are grouped into schools, and you want to use the numeric data to group the students by school. This is an example of binning data, where the bins represent ranges of values, and the If statement is an easy way to assign the dif...
In this demonstration, we'll take a look at Boolean functions, as well as the If function I'm going to get a script editor window. And again, the keyboard shortcut is Ctrl+T or you can go to the File menu, use the toolbar. Many different ways to get that new Script Editor window. And let me bring the log in front of the journal. Back in the Script Editor window, I'm going to type the co...
It's common to have conditions that are limited to specific values, and these values could be numeric or character data. You can use the Match function in this situation. The Match function is a specialized conditional function that takes three or more arguments. The first argument is evaluated and used as the value to be matched. The second argument is evaluated and interpreted as a Bo...
In this demonstration, we'll see how to use the match and choose conditional functions. So in the course journal, in section I'm going to click on Concrete Strength Data. And so the Concrete Strength data includes this column called Concrete Type, which indicates the brand of concrete mix and whether it was reinforced or not, if it was just standard during whatever this test was. And le...
Working with data tables is, of course, an important part of working with JMP. The data table enables JMP to access your data through various analysis and graphing platforms. You can enter your data directly into a JMP data table, and you can save that data table for future access. Or, you might have data saved in a different file format, or in a relational database. In those cases, you...
In order for your script to open your data table, it has to tell JMP where to find the table. So, you need to understand how file paths work. The path to a file starts from the root (or disk drive) and continues with the sequence of folders that leads to the folder where the file is saved. So, the sequence reflects the series of folders that JMP has to navigate, starting at the root, in...
Often, you want the script user to be able to choose a directory or file when the script runs. This is how your script can obtain the absolute file path, no matter who's using the script. You can use the Pick Directory function with an optional prompt argument, and JMP will open the Browse for Folder dialog and allow the user to navigate to and select a directory. The optional prompt ap...
So here we're going to see how to use scripts to open JMP data tables. So I'll get a new Script Editor window and I'm going to use the pick directory function to prompt the user when the script runs to navigate to a directory or folder. And I'm going to store that result in the variable myPath. And here notice with the variable name, I'm using an example of what we call camel case where...
When your data are saved in a computer file that's not a JMP data table, you can import it into JMP in order to create a JMP data table. The original source file might be a text file, a Microsoft Excel workbook, or a file saved from a relational database. Whether your data are stored in a JMP data table or some other file format, you use the Open function to access your data. When you u...