cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar

Variables

Started ‎11-08-2022 by
Modified ‎11-08-2022 by
View Fullscreen Exit Fullscreen

OK, so now let's talk about variables. You can use variables to store values that aren't constant from one time a script runs to another. These values can be data of any type, data structures of any kind, or references to another object. Unlike in many programming languages, JMP variables don't need to be declared, or listed at the start of the script, and they're not limited to storing any particular data type. So you can assign a new value to an existing variable at any time, and that new value doesn't have to be the same type of data or reference as the old value. Variables also have a scope, which is the defined area and time within JMP where they're available for use. The area in which a variable is available is also known as its namespace--the space where that name is associated with a particular value or object reference. By default, variables are global, meaning they exist in the global namespace. A global variable is available everywhere in JMP for as long as the current JMP session exists. In other words, global variables persist until you exit JMP. Let's suppose you create a global variable, s, that stores a sum your script has calculated. Any script that runs during your current JMP session has access to that variable. However, it's important to consider that if you tend to use the same variable names in multiple scripts, such as s for a sum, or i for a counter, those values might collide with one another. In other words, you might not intend for the s in the second script to overwrite the value of the s in the first script, but if both scripts use a global variable with the same name, then that's exactly what will happen, because you can't have different copies of the same-named global variable. So it can be useful to restrict the scope of the variable so that it's only available to a limited area or for a limited time. One way to accomplish that is to use local variables. These are variables that are restricted to a limited namespace, meaning they're only available temporarily while a portion of the script is running. You use the Local function to create local variables, and these can be a good way to manage the names in your scripts and avoid collisions in the global namespace. Another alternative to using global variables is using the Here namespace. Using the Names Default to function in your script, with a as its Boolean argument, creates a unique Here namespace for any script. This allows you to restrict the scope of the variables to an individual script without using the Local function. You can create and manage other namespaces as needed, and JMP includes some other predefined namespaces in addition to the Global, Here, and Local namespaces.