Subscribe Bookmark RSS Feed

get rows where and select where

vince_faller

Super User

Joined:

Mar 17, 2015

I'm seeing a weird issue with get rows where when trying to make it dynamic.

dt = Open("$SAMPLE_DATA\Big Class.jmp");

dt << get rows Where(:Sex == "F"); //Works

dt << Get Rows Where(Column("Sex") == "F"); // Doesn't Work

//but ...

col = :Sex; //doesn't work

col = Column("Sex"); //Works

//so trying to do

dt << Get Rows Where (col == "F");

//can't work in any way that I can see


Tried a few different versions.  Anyone else getting this?  I swear I've done this before.  I tried :Name as well but it doesn't like using a variable and doing some type of Eval seems pretty hacky for this. 

1 ACCEPTED SOLUTION

Accepted Solutions
Solution

An empty index appears to be needed to access the data of a column when the current row is implicit. Alternatively As Column() can be applied to a column name (as string) or a variable.

dt << Get Rows Where(Column("Sex")[] == "F"); // Works

col = Column("Sex"); //Works

dt << Get Rows Where(col[] == "F"); // Works

dt << Get Rows Where(As Column(col) == "F"); // Works

dt << Get Rows Where(As Column("sex") == "F"); // Works

5 REPLIES
vince_faller

Super User

Joined:

Mar 17, 2015

I could do

col = Column("Sex")<<Get Values;

Loc(col,"F");


But I still think something within the data table should work.

Solution

An empty index appears to be needed to access the data of a column when the current row is implicit. Alternatively As Column() can be applied to a column name (as string) or a variable.

dt << Get Rows Where(Column("Sex")[] == "F"); // Works

col = Column("Sex"); //Works

dt << Get Rows Where(col[] == "F"); // Works

dt << Get Rows Where(As Column(col) == "F"); // Works

dt << Get Rows Where(As Column("sex") == "F"); // Works

vince_faller

Super User

Joined:

Mar 17, 2015

Yep.   Column("Sex")[row()] was how I was doing it before.

Thank you

pmroz

Super User

Joined:

Jun 23, 2011

One more wrinkle.  I use strings for the column names, rather than pointers to the column.  This works:

dt = Open("$SAMPLE_DATA\Big Class.jmp");

col = "Sex";

srows = dt << get rows Where(as column(dt, col) == "F");

This works too:

srows = dt << get rows Where(as column(col) == "F");

ram

Contributor

Joined:

Jun 5, 2017

better solution;

dt = Open("$SAMPLE_DATA\Big Class.jmp");

col1="height"; val="61"; val2="95";

srows = dt << get rows Where(char(column(col1)[]) == char(val) );