Search code examples
sas-jmpjsl

jmp script logic works as jsl but not as add-in


I run JMP 15.2.0 and my jsl script includes this section of code, which has a minor bug:

for each row(
    if (:ColumnA == 99, ColumnA = .)
);

The 2nd ColumnA should have a leading : in order to replace 99's with null. But for some reason this works, despite the bug, when run via JMP as a script, yet not when installed as an "Add-In".

Why would the exact same script work (i.e., 99's get nullified as intended) when run as a script, but not as an "Add-In" (99's remain and no error appears in the log)?

Shouldn't jsl be interpreted the same whether run through JMP as a script or as an "Add-In"? Could my JMP instance be somehow set to use different engines for different modes? Has anyone else observed this confounding JMP strangeness?


Solution

  • The reason this happens is due to how JMP handles scope. When you give an unscoped variable (is not of the form ns:var, :var, ::var), then JMP has a sequence to try to find the proper scope for the variable of interest. It goes something like this

    1. Check local namespace -- if found, done
    2. Check Current Data Table columns, if found, done
    3. Check here namespace -- if found, done
    4. Check global namespace -- if found, done

    Since you did not define "Column A" anywhere in your script, the only valid name for which "Column A" applies is the column name.

    Inside of a "For Each Row" statement the order is to check column names first (higher precedence than any other scope).

    Update: Note that the above list is for explicitly unscoped variables without any 'unscoped variable handling' -- that is, no "Names Default to Here( 1 )" line. Note that if you have that line starting the script then it does not affect the data table, as the unscoped "ColumnA" variable only ever gets placed within the Here namespace. JMP doesn't do scope-walking to see if it can find a "ColumnA" variable in the various listed namespaces above.

    I've included a picture of the most common way of attaching a script to an addin -- this is what I'm assuming you're doing. Notice that by default the line 'Use the "Here" namespace for unqualified JSL variable names' is checked -- unqualified means has no colon (unscoped). This check-box is forcing JMP to only look at Here:ColumnA when seeing the unscoped variable. You need to run the script without any automatic scope control to work as it does when run as a standalone.

    Addin scripts by default link unscoped variables to the "Here" namespace, making it so that unscoped column names don't work