Scripting Data Filters

A question that I’ve been asked a few times is “how can I script a data filter?”.  My response to this question is always the same: “why would you want to do this?”.

In scripting, a common task is to manipulate data through row selections; a data filter is a tool that allows you to perform the same task interactively  without scripting.  Which means: you either script or you use a data filter.

So now the question becomes: “how can I implement functionality equivalent to a data filter using JSL?”.

In this post I will look at answering this question.  But since there are occasions where is is desirable to explicitly script the data filter, I’ll look at that too!

To make this illustration concrete, I need an example.

I’m going to use one of my favourite sets : the Movies table in the JMP sample data:

This is a great set of data for creating treemaps. So let me look at some treemaps that can be created in conjunction with local data filters.  I can create the treemaps using either Graph Builder of the Treemap platform.  I’m going to use the later – simply because code for Graph Builder tends to be more verbose:

treemap-data-filter

The treemap shows “tiles” for directors, sized by domestic revenue.  Using the data filter I can select movies of specific genres (“type”) or movies that have a particular rating.  Of course I can also construct a filter which is a composite of both.  Let me select PG-rated dramas:

treemap-pg-drama

Now let me take this piece of output in isolation and look at how to create it using JSL. I do this simply by asking JMP to save the script to the script window:

What if I want to use this code as the basis for iterating over the various combinations available in the data filter.  I should be able to create output for all combinations of type and rating:

This will create 24 separate windows.  Each will have its own filter and together the windows will cover all the combinations of type and rating.

What if I simply wanted to use the filter to create the 24 graphs so that I could save them as pictures?

In this case it is better to simply use JSL to implement the equivalent functionality to the data filter.  One way is to make row selections and use the hide and exclude properties associated with rows.  But instead I will take advantage of a where-clause that can be built into the platform, as illustrated below:

Using this syntax, I can now write the following code:

If you copy this script – note that the pictures are saved to the “current folder”.  This folder is the same folder that contains the script – which is undefined until you save the script!

Leave a Reply

Your email address will not be published. Required fields are marked *