Depending on the complexity of your script, it might be obvious that ratio is a variable and height and weight are data table column names. But what if the meanings are ambiguous? A script might use ratio as a global variable and as column names.
The syntax Scale( "Log" ) is preferred for setting a string literal. To catch ambiguous instances, set the “Allow Unquoted Strings in JSL” General preference to “Yes (with a warning)” or “No”.
JMP interprets object names using name resolution. The following rules are applied sequentially to unscoped names:
If a name is not preceded by the : scoping operator, look it up in a namespace, such as Global or Here.
If a name is followed by a pair of parentheses (), look up the name as a built-in function (not a user-defined function).
If a name is preceded by the : scoping operator, look it up as a data table column or table variable.
If a name is preceded by the :: scoping operator, look it up as a global variable.
If a name is used as the left side of an assignment (the L-value) and Names Default To Here(0) is at the top of the script, create and use a global variable.
Using scoping operators is an easy way to help JMP resolve ambiguous names (for example, when a name refers to both a variable and a column name).
In the following example, the prefix double-colon operator (::) identifies z as a global variable. The single-colon prefix operator (:) identifies x and y as column names.
Tip: The Names Default to Here(1) function also affects name resolution. See Names Default To Here and Global Variables in Programming Methods for details.
As Column(dt, name)
Forces name to be evaluated as a data table column. The optional data table reference argument, dt, sets the current data table. See Scoped Column Names for examples.
Forces name to be evaluated as a global variable.
The prefix colon (:) means that the name refers to a table column or table variable only, never a global variable. The prefix colon refers to the current data table context.
The infix colon (:) operator extends this notion by using a data table reference to specify which data table has the column. This is particularly important when multiple data tables are referenced in a script.
In the following example, the dt variable sets the data table reference to Big The infix colon separates the data table reference and age column.
As Column achieves the same results:
The Column function can also identify a column. For Big, the following expressions all refer to age, the second column in the table:
When you run a script that includes a column and variable with the same name, an Invalid Row Number error occurs. To prevent this problem, use unique column and variable names, or scope the names as follows:
or the name is subscripted (for example, the subscript [1] in weight[1] selects the first value in the weight column).
Specify the row number with the Row() function. In the following example, the row is set to 3. The height in that row is divided by the weight, and the result is assigned to the ratio global variable.
Row() = 3;
When you reference a column name using As Name(), and Names Default To Here(1) is set, JMP returns a variable reference. That reference is then processed using the standard reference rules.
In the following example, there is no height variable in the Here: scope, so JMP returns an error.
Use As Column() instead of As Name():
Explicitly scope height with As Name():
These scripts return 55, the value of height in the third row of Big
Name resolution errors can also occur when a variable and unquoted keyword have the same name. For example, one argument for <<Preselect Role() is “Y”. Quote this argument if your script also uses Y as a variable.
Note: The current row in a JSL script is not determined by selecting rows or positioning your cursor in the row. The current row is defined to be zero (no row) by default. You can set a current row with Row() (for example, Row() = 3). Please note that such a setting only lasts for the duration of that script. Then, Row() reverts to its default value, zero. This behavior means that submitting a script all at once can produce different results than submitting a script a few lines at a time.
Another way to establish a current row for a script is to enclose it in For Each Row(). This method executes the script once for each row of the current data table. For an example, see If. See Data Tables section for more information about working with data tables.
Yes. Once you use a scoping operator with a name, that name continues to be resolved accordingly for all subsequent occurrences of the name. For example, a script might contain a column and a variable named age. When you declare the global variable age with the scoping operator :: at the beginning of the script, age is always interpreted as a global variable in the script. The values in the age column are not affected by the variable.