cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
lwx228
Level VIII

How do write a JSL that implements one of the conditions for selecting a subset using cell values?

For example, in "Big Class.jmp": add" add" column,And change the value of the first row of the "add" column to "&:height<65". How do code JSL to add the condition in the first row of the "add" column?

 

 

Make the JSL function of this combination the same as that of the following code:

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << Select Where( sex == "F" & :age > 14 & :height < 65 );
d3 = dt << Subset( Output Table( "test" ), Selected Rows( 1 ), selected columns( 0 ) );

2021-07-07_163759.png

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions

Re: How do write a JSL that implements one of the conditions for selecting a subset using cell values?

This is definitely possible, but have you ruled out using a (global) data filter? This would let you--and those who are not scripters--enter queries easily, saving your favorites, and saving the filter off to the data table for future use.

 

Once favorites exist, they are easily accessible from a drop-down menu.

 

This is a really easy way to go (and to teach to your script-averse co-workers, who may be the end-users?). The cell-based approach will require end-users to enter legitimate syntax--far from guaranteed.

 

Once you've set this up, the users just need to pick from a drop-down. More advanced users can add their own filters. Selections are made immediately, so all that remains is actually creating the subset.

 

brady_brady_0-1625678810086.png

 

If, on the other hand, you need to stick with your initial approach, here is a way to do it:

 

Names Default To Here(1);

//setup
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << new column("add");
dt:add[1] = " & :height < 65";

//using \[ and ]\ to delimit the initial :sex == "F" string means you don't have to escape double-quotes.
query text = "\[:sex == "F"]\" || dt:add[1];

//parse and substitute the actual query text in for _TXT_ in the first expression below, and evaluate
eval (substitute( 
	expr ( dt << Select Where( _TXT_ ) ),
	expr( _TXT_),
	parse(query text)
));

dtSub = dt << subset (selected rows(1), selected columns(0));

 

Cheers,

Brady

View solution in original post

4 REPLIES 4
lwx228
Level VIII

Re: How do write a JSL that implements one of the conditions for selecting a subset using cell values?

I tried to code this way, but it didn't work.

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
New Column( "add", Character, "Nominal" );
dt[1, "add"] = "&:height<65";
a = dt[1, "add"];
dt << Select Where( :sex == "F" & :age > 14 || a );
d3 = dt << Subset( Output Table( "test" ), Selected Rows( 1 ), selected columns( 0 ) );

 

I want to know how to code this form of selection of subsets using the values of cells as conditions.

 

Thanks Experts!

lwx228
Level VIII

Re: How do write a JSL that implements one of the conditions for selecting a subset using cell values?

This code uses the contents of the cell directly to calculate the values in the column formula.

But I don't know how to apply this form to code that selects subsets.

Thanks!

 

aaa = dt[r, "abc"];

Eval( Parse( "Column(d9,\!"test\!")<<Formula(" || aaa || ")" ) );

d9 << run formulas;
Column( "test" ) << deleteFormula;

Re: How do write a JSL that implements one of the conditions for selecting a subset using cell values?

This is definitely possible, but have you ruled out using a (global) data filter? This would let you--and those who are not scripters--enter queries easily, saving your favorites, and saving the filter off to the data table for future use.

 

Once favorites exist, they are easily accessible from a drop-down menu.

 

This is a really easy way to go (and to teach to your script-averse co-workers, who may be the end-users?). The cell-based approach will require end-users to enter legitimate syntax--far from guaranteed.

 

Once you've set this up, the users just need to pick from a drop-down. More advanced users can add their own filters. Selections are made immediately, so all that remains is actually creating the subset.

 

brady_brady_0-1625678810086.png

 

If, on the other hand, you need to stick with your initial approach, here is a way to do it:

 

Names Default To Here(1);

//setup
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << new column("add");
dt:add[1] = " & :height < 65";

//using \[ and ]\ to delimit the initial :sex == "F" string means you don't have to escape double-quotes.
query text = "\[:sex == "F"]\" || dt:add[1];

//parse and substitute the actual query text in for _TXT_ in the first expression below, and evaluate
eval (substitute( 
	expr ( dt << Select Where( _TXT_ ) ),
	expr( _TXT_),
	parse(query text)
));

dtSub = dt << subset (selected rows(1), selected columns(0));

 

Cheers,

Brady

lwx228
Level VIII

Re: How do write a JSL that implements one of the conditions for selecting a subset using cell values?

Thank brady!

This is exactly the JSL I need so that I don't need to use if().