cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Register to attend Discovery Summit 2025 Online: Early Users Edition, Sept. 24-25.
  • New JMP features coming to desktops everywhere this September. Sign up to learn more at jmp.com/launch.
Choose Language Hide Translation Bar
peter_t
Level I

How do I get rows based on dynamic column selection in JSL

In a JMP script I would like to retrieve the rows matching a certain criteria specified by user. I would like to do something similar to this:

 

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
r = dt << Get Rows Where( :sex == "M" );
Show( r );

Only where the criteria is selected by the user, i.e. the column ("sex") and the target value ("M") should be dynamic. I have tried this without luck:

colname=Column(dt,"sex");
target="M";
r2 = dt << Get Rows Where( colname == target );
show(r2);

What am I doing wrong?

 

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: How do I get rows based on dynamic column selection in JSL

Issue is with your colname

 

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");

colname = Column(dt, "sex");
target = "M";
r2 = dt << Get Rows Where(As Column(colname) == target);
Show(r2);

or in my opinion better option

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");

colname = "sex";
target = "M";

r2 = dt << Get Rows Where(As Column(dt, colname) == target);
Show(r2);

or

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");

colname = "sex";
target = "M";

r2 = dt << Get Rows Where(Column(dt, colname)[Row()] == target);
Show(r2);

 

-Jarmo

View solution in original post

1 REPLY 1
jthi
Super User

Re: How do I get rows based on dynamic column selection in JSL

Issue is with your colname

 

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");

colname = Column(dt, "sex");
target = "M";
r2 = dt << Get Rows Where(As Column(colname) == target);
Show(r2);

or in my opinion better option

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");

colname = "sex";
target = "M";

r2 = dt << Get Rows Where(As Column(dt, colname) == target);
Show(r2);

or

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");

colname = "sex";
target = "M";

r2 = dt << Get Rows Where(Column(dt, colname)[Row()] == target);
Show(r2);

 

-Jarmo

Recommended Articles