Share your ideas for the JMP Scripting Unsession at Discovery Summit by September 17th. We hope to see you there!
Choose Language Hide Translation Bar
Highlighted
Kelly
Level III

How can I make a conditional subset table without directly calling a column name?

The first 3 lines of this script create a new data table where heights are less than 60. This part runs fine.
For the function that I would like to develop I would like to reference a column in a different way than using :height.

 

I have tried 4 different ways to reference the column, but none of them work. I have used the column function and get column reference function (please see below).

 

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
//This one works
dtSubgroup = dt << Subset(Rows(dt << get rows where(:height < 60)));
//None of these work
dtSubgroup = dt << Subset(Rows(dt << get rows where(Column("height") < 60)));
dtSubgroup = dt << Subset(Rows(dt << get rows where(Column(dt, "height") < 60)));
dtSubgroup = dt << Subset(Rows(dt << get rows where(Column(4) < 60)));
refList = dt << Get Column Reference( {"height"} );
dtSubgroup = dt << Subset(Rows(dt << get rows where(refList[1] < 60)));

Is there any reason why they do not work?
Any suggestion on a solution?

Thank you for your help.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Re: How can I make a conditional subset table without directly calling a column name?

Try appending empty square brackets after the closing parenthesis of the Column() function. Like this:

 

Column("height")[] < 60

Does this change help?

Learn it once, use it forever!

View solution in original post

3 REPLIES 3
Highlighted

Re: How can I make a conditional subset table without directly calling a column name?

Try appending empty square brackets after the closing parenthesis of the Column() function. Like this:

 

Column("height")[] < 60

Does this change help?

Learn it once, use it forever!

View solution in original post

Highlighted
Kelly
Level III

Re: How can I make a conditional subset table without directly calling a column name?

Thanks, this did exactly what I wanted.
May I ask why this works?
I have used the column function many times without using square brackets.
What is different about this case? What is the rule to follow?
Highlighted

Re: How can I make a conditional subset table without directly calling a column name?

It does seem odd, doesn't it?

 

It is all about context. For example, you might use this in a column formula:

 

If( Column("height") < 60, 0, 1 ); // implicit assignment of Row() = current row number

 

Or you might use it in the For Each Row() function to accomplish the same thing in a script:

 

For Each Row(
	// implicit assignment of Row() = current row number
	If( Column("height" ) < 60,
		:status = "small",
		:status = "large"
	)
)

The context of the column formula and the iteration above is such that JMP is implicitly setting the Row() function for you. So JMP uses that information to figure out where to get or store the value (i.e., which row). That is not the context of the general case here:

 

dtSubgroup = dt << Subset(Rows(dt << get rows where(Column("height") < 60)));

The data table does not implicitly use the current row number when you tries to evaluate the comparison. You force it to by adding the empty subscript operator, [ ].

Learn it once, use it forever!
Article Labels

    There are no labels assigned to this post.