Handling Column References

JSL is often described as a scripting language.  Personally I think that doesn’t do it justice.  I prefer to think of it as a programming language.  The difference?  For me an obvious difference is that instead of using hard-coded values I want to use variables.  In particular I want to use variables to handle column references.

The Column Function: Generating Column References

The start point for scripting a JMP platform is to create the platform interactively and then save the associated script (from the red triangle: Save Script>To Script Window).

If I always want weight on the y-axis and height on the x-axis then  I can use this script as-is.  But this is where I make a distinction between scripting and programming.  When I write programs, I want them to be general purpose, and that means replacing the column references with variables:

If you have a data table that  contains column names that are not programmer-friendly the JMP generated code looks slightly different:

But still the Column function can be used to generate a valid column reference from the literal name of the column:

This example is based on the Bivariate platform, the principle is general.  Here is an example using Graph Builder:

JMP-generated code:

Code generalised using variables:

Handling Send To Report Messages

If I perform graphical edits the JMP generated codes becomes significantly more complex.  In the following example I have chosen to add grid-lines for both the x-axis and y-axis:

Notice in particular that the lines to ‘show major grid’ contain explicit references to the names of the columns.  So these also need to be replaced with variables:

Here is another example, based on changing the font size for the axis labels:

JMP-generated code:

Code generalised using variables:

Handling Lists of Columns

Some platforms take a sequence of column references:

In this example the multivariate analysis is performed on 4 variables.  Whilst the code could be generalised using 4 variables to represent the columns the code wouldn’t be fully general: what if I wanted 5 variables in the analysis?

Structurally, from a programming perspective, I want to use a list data structure to contain the column references.  But will JMP allow me to do that – there is only one way to  find out:

This works!  The curly braces {…} collect all of the column references together into a single list structure.   Now I ought to be able to simple replace the explicit list with a variable reference:

Unfortunately, and perhaps surprisingly, this doesn’t work.  We’ve done nothing wrong – everything is consistent with how computer code ought to work.

However, there is a curious feature of the scripting language – expressions are evaluated inwards, starting from the outside, whereas most languages evaluate inner parts first.  There is a word for this – frustratingly I have forgotten it -does anyone know?

Armed with this knowledge I can explicitly ask JMP to evaluate the list variable before evaluating entire statement:

In practice I would also want to write some code to populate the list:

Using List Variables

List of column references can also be used in places where you might not expect.  Below is the JMP generated code for the distribution platform:

Generalising this code whilst maintaining this code structure would be difficult.  Fortunately a list variable can be used to achieve the same result (for most platforms):

Dynamical Construction of Expressions

The above example of list usage doesn’t work with Graph Builder.  Assume I want to plot multiple y-variables overlaid against a common x-variable.  If I don’t know how many y-variables will be plotted then I have to resort to building up the appropriate expression using substitution methods (see this earlier post for a more detailed discussion):


Share the joy:

One thought on “Handling Column References”

Leave a Reply