Subscribe Bookmark RSS Feed

How can I find rows that have elements of my list ?

uday_guntupalli

Community Trekker

Joined:

Sep 15, 2014

Hello All,

            I am wondering as to what is the best way to achieve this. I have a list of elements and a data table . I want to figure out the easiest way to select all rows in one column that have the elements of my list (inclusive of duplicates) . The code that I am using is :

for(i = 1, i<= N Items(CheckList),i++,

dt_List << Select Where(Pat Match(:ColName,CheckList[i]) == 1);

dt_List << Label ; 

   );

dt_List << Select Labelled Rows ;

where CheckList - is my list for e.g. CheckList = {1,2,3,4} ;

          :ColName - is the name of my column
           dt_List - is the name of the data table I am working with
      
         The above piece of code only selects only the rows for the last item of my list . However , the label shows up on the appropriate rows.

Best

Uday

Best
Uday
1 ACCEPTED SOLUTION

Accepted Solutions
Solution

I'm a little nervous over the use of the word 'best' above, but here's one way:

NamesDefaultToHere(1);

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

// Make a list of unique ages, removing a couple of items at random

mylist = AssociativeArray(Column(dt, "age") << getValues) << getKeys;

RemoveFrom(myList, RandomInteger(1, NItems(myList)), 1);

RemoveFrom(myList, RandomInteger(1, NItems(myList)), 1);

Print(myList);

// Select the requisite rows

r = dt << getRowsWhere(Contains(myList, :age));

dt << selectRows(r);

2 REPLIES
Solution

I'm a little nervous over the use of the word 'best' above, but here's one way:

NamesDefaultToHere(1);

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

// Make a list of unique ages, removing a couple of items at random

mylist = AssociativeArray(Column(dt, "age") << getValues) << getKeys;

RemoveFrom(myList, RandomInteger(1, NItems(myList)), 1);

RemoveFrom(myList, RandomInteger(1, NItems(myList)), 1);

Print(myList);

// Select the requisite rows

r = dt << getRowsWhere(Contains(myList, :age));

dt << selectRows(r);

uday_guntupalli

Community Trekker

Joined:

Sep 15, 2014

Ian@JMP​ :
             Thanks for your response. I have found the following helpful too :

MyList = {"611","680","323","410"};

dt << select where(contains(MyList, char(:ColName)));


Alternatively :
dt << Select Where(Pat Match(:ColName,CheckList[i]) == 1, current selection("extend"));

These were suggestions I received from other resources and I hope it will help the next guy .

Best

Uday

Best
Uday