The World Statistics Day celebration continues here in the Community. We all need reliable data for sound decision making. Do you have a data source that you trust most? Head over to Discussions to tell us about it.
Choose Language Hide Translation Bar
Highlighted
elizperez
Level II

JSL: Select Where with variable for column name

Hi I'm trying to use select where to count the number of rows which meet criteria in 2 columns using a for loop. In the beginning of my script (not shown) I use a dialog to let the user choose 2 columns and this ends up in a list (collist). I then use an associative array on each to determine the unique values per column. A second dialog allows the user to choose a subset of those unique values per column which ends up in another list (poschosen). The problem I'm struggling with is inserting the columns from collist into the select where function. I've tried a bunch of different attempts at eval, expr, eval expr, parse, etc. to try to insert them appropriately but I just can't seem to find the correct way. I'm hoping someone has advice.

Here is my code adapted for the Sample Data: Children's Popularity. I'd like to replace the values (line 14) School and Goals to be collist[1] and collist[2] respectively. Thank you for your help in advance Elizabeth


dattable=Open( "$SAMPLE_DATA/Children's Popularity.jmp" );


poschosen={"Ridge","Sand","main","stop","Popular","Grades","stop"};


stoppos={4,7}; //determine the position of the separator "stop"


Test1pos=subtract(stoppos[1],1); //determine the # of school column values chosen


Test2posStart=add(stoppos[1],1); //determine where in the list the Goals column values start




collist={"School", "Goals"};


sumpositives=0;


For (i = 1, i <= Test1pos, i++, //loop through the chosen school column values




For(f=Test2posStart, f<stoppos[2],f++, //loop through the chosen Goals column values


dattable<<select where(School==poschosen & Goals==Poschosen);


num_selected=nrows(dattable<<get selected rows); //count the rows selected




sumpositives=sumpositives+num_selected; //add the current selection count to previous count


print(sumpositives); //should be 56 in this example


); //end of inner for loop


); //end of outer for loop


1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
elizperez
Level II

Re: JSL: Select Where with variable for column name

Nevermind I just figured it out (of course right after I post the question, doh)... line 14 works when I do this:

dattable<<select where(as column(dattable,collist[1])==poschosen & as column(dattable,collist[2])==Poschosen);

View solution in original post

2 REPLIES 2
Highlighted
elizperez
Level II

Re: JSL: Select Where with variable for column name

Nevermind I just figured it out (of course right after I post the question, doh)... line 14 works when I do this:

dattable<<select where(as column(dattable,collist[1])==poschosen & as column(dattable,collist[2])==Poschosen);

View solution in original post

Highlighted
kwtorek0
Level I

Re: JSL: Select Where with variable for column name

I've been trying forever to figure this one out, finally found this thread. Thank you!

Article Labels

    There are no labels assigned to this post.