cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar

Changing the filter in a for loop

Hi,

Using a For Loop, I am trying to do some analysis in JMP and each time a series of rows are filtered for this analysis. My code is similar to the snippet below. The problem is that the filter does not change in each iteration and the filter is implemented only the first time. I tried to figure out a solution by reading the JMP Help PDF, but none of them helped.

dt = Open(path to the file);

For( i = 1, i <= 10, i++,
df = dt << Data Filter(Invisible, Mode( Show( 1 ), Include( 1 ) ), 
Add Filter( Columns( Tester ), Where( Tester = testerNames[i] ) ) );

Some analysis

print the report
);
1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Changing the filter in a for loop

Move filter outside the for loop and use << Where to change the filter values

Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");
df = dt << Data Filter(
	Mode(Show(1), Include(1)),
	Add Filter(Columns(:Name))
);
names = Associative Array(:name) << get keys;
For(i = 1, i <= 10, i++,
	df << (Filter Column(:name) << Where(:name == names[i]));
	wait(1);
);
-Jarmo

View solution in original post

3 REPLIES 3
jthi
Super User

Re: Changing the filter in a for loop

Move filter outside the for loop and use << Where to change the filter values

Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");
df = dt << Data Filter(
	Mode(Show(1), Include(1)),
	Add Filter(Columns(:Name))
);
names = Associative Array(:name) << get keys;
For(i = 1, i <= 10, i++,
	df << (Filter Column(:name) << Where(:name == names[i]));
	wait(1);
);
-Jarmo

Re: Changing the filter in a for loop

@jthi answered your question, but I wonder if it is the best approach, to begin with. You are scripting your analysis so you can use row state functions directly instead of employing a data filter as an intermediary. This approach would select rows that meet a criterion and perform the analysis.

 

I am not against your approach, but data filter objects are primarily intended for interactive analysis. They are not the only way to filter your data with a script.

SDF1
Super User

Re: Changing the filter in a for loop

Hi @LoglinearRange8 ,

 

  Although @jthi has answered your question, I think one of the reasons your code isn't working as expected is because you weren't closing down the Data Filter window. If you add a df<<Close command inside your For Loop it should close down the data filter window (which is invisible, and why you don't see what's happening at each step in the for loop). Once you've created that Data Filter window, it remains open and you need to re-define the filter at each iteration, hence @jthi 's solution to move the filter outside the for loop and only have the selections inside the for loop.

 

  You might also look into another thread from @Mark_Bailey here that shows how you can script this from the Scripting Index.

 

  I also agree with @Mark_Bailey , this might not be the best approach for automating your workflow. There could be better ways to to perform the data analyses.

 

Hope this helps!,

DS