Share your ideas for the JMP Scripting Unsession at Discovery Summit by September 17th. We hope to see you there!
Choose Language Hide Translation Bar
Highlighted
TWE
TWE
Level I

data filter for loop II

Hi,

 

I have a data table which is updated (in the original script via query) e.g. every 5s and will be appened to another table. So far so good. How can I get it that the selction will not be cleared after each iteration?

Names Default To Here(0);
dt0 = New table ("Test",
	New Column( "name", Character,"Nominal"), 
	New Column( "age", numeric, continuous), 
	New Column("sex",  Character,"Nominal"), 
	New Column("height", numeric, continuous),
	New column("weight", numeric, continuous,));
df = dt0 << Data Filter(
Add Filter( Columns( :sex ) )
);
n=0; 																				
e=10; 																				
startwork = Function( {}, 
dt1=Open( "$sample_data/big class.jmp");
dt0 << Concatenate( current data table(), "Append to First Table");
n+=1;
Close (dt1, nosave);
if(n<e, Schedule(5, startwork() ); ,Schedule( 0, 0)););
startwork();
dt0 << Graph Builder(
	Size( 534, 464 ),
	Show Control Panel( 0 ),
	Variables( X( :weight ), Y( :height ) ),
	Elements( Points( X, Y, Legend( 3 ) ), Smoother( X, Y, Legend( 4 ) ) )
);

It would be great if my selction will be valid for the data table and graph after every iteration until the section will be changed by the user.

Many thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
txnelson
Super User

Re: data filter for loop II

Here is a slightly different approach.  It uses the << Get Script message from the "Test" data filter, and then does a slight modification, and then applies it to the Big Class data table.  The whole thing is triggered by the Filter Change Handler applied to the data filter on the test data table.

Names Default To Here( 0 );

dt1 = Open( "$sample_data/big class.jmp" );

dt0 = New Table( "Test",
	New Column( "name", Character, "Nominal" ),
	New Column( "age", numeric, continuous ),
	New Column( "sex", Character, "Nominal", Values( {"F", "M", "F", "M", "F", "M", "F", "M"} ) ),
	New Column( "height", numeric, continuous ),
	New Column( "weight", numeric, continuous, )
);
df0 = dt0 << Data Filter( Add Filter( Columns( :sex ), /* variable get where selection df0*/ ) );
f = Function( {a},
	dschar = Char( df0 << get script );
	Try( df1 << close );
	dschar = "df1 = dt1 " || Substr( dschar, 21 );
	Eval( Parse( dschar ) );
	Try( df1 << close );
);
rs = df0 << Make Filter Change Handler( f );

You also may want to explore the ability to subset your main data table, or to create a summary data table from your main table, and to use the option, to "Link to Original Table".  You can then place a data filter on the subsetted or summarized data table, and it will automatically replicate the changes in the original table. 

Jim

View solution in original post

4 REPLIES 4
Highlighted
txnelson
Super User

Re: data filter for loop II

I suggest that before the update, that you retrieve the Where Clause from the Data Filter, then do the update, and then reapply the retrieved Where Clause.

See

     Help==>Scripting Index==>Data Filter..........

for details and example

Jim
Highlighted
TWE
TWE
Level I

Re: data filter for loop II

Thanks for your answer. Unfortunatly I couldnt get the hint out of the Help==>Scripting Index==>Data Filter..........

I have tried multiple options but nothing works.

How can I get the where clause or the where argument as a variable from df0 and put it to the df1 as where argument?
I found the << get where clause but this is just a text format...

Names Default To Here(0);
dt0 = New table ("Test",
	New Column( "name", Character,"Nominal"), 
	New Column( "age", numeric, continuous), 
	New Column("sex",  Character,"Nominal", Values({"F", "M", "F", "M", "F", "M", "F", "M"})), 
	New Column("height", numeric, continuous),
	New column("weight", numeric, continuous,));
df0 = dt0 << Data Filter(
Add Filter( Columns( :sex ),/* variable get where selection df0*/ )
);

dw0 = df0 << get where clause;

dt1=Open( "$sample_data/big class.jmp");
df1 = dt1 << Data Filter(
Add Filter( Columns( :sex) /* set where selection from df0*/ )
Highlighted
txnelson
Super User

Re: data filter for loop II

Here is a slightly different approach.  It uses the << Get Script message from the "Test" data filter, and then does a slight modification, and then applies it to the Big Class data table.  The whole thing is triggered by the Filter Change Handler applied to the data filter on the test data table.

Names Default To Here( 0 );

dt1 = Open( "$sample_data/big class.jmp" );

dt0 = New Table( "Test",
	New Column( "name", Character, "Nominal" ),
	New Column( "age", numeric, continuous ),
	New Column( "sex", Character, "Nominal", Values( {"F", "M", "F", "M", "F", "M", "F", "M"} ) ),
	New Column( "height", numeric, continuous ),
	New Column( "weight", numeric, continuous, )
);
df0 = dt0 << Data Filter( Add Filter( Columns( :sex ), /* variable get where selection df0*/ ) );
f = Function( {a},
	dschar = Char( df0 << get script );
	Try( df1 << close );
	dschar = "df1 = dt1 " || Substr( dschar, 21 );
	Eval( Parse( dschar ) );
	Try( df1 << close );
);
rs = df0 << Make Filter Change Handler( f );

You also may want to explore the ability to subset your main data table, or to create a summary data table from your main table, and to use the option, to "Link to Original Table".  You can then place a data filter on the subsetted or summarized data table, and it will automatically replicate the changes in the original table. 

Jim

View solution in original post

Highlighted
TWE
TWE
Level I

Re: data filter for loop II

For the case that I implement the script into a loop (like the first question), the selection is just valid based on the row numbers. I need the selection based on the column selection. For that I found a possible workaround:

Construct a list box and use this selection for the table:

Names Default To Here(0);

dt0 = New table ("Test",
	New Column( "name", Character,"Nominal"), 
	New Column( "age", numeric, continuous), 
	New Column("sex",  Character,"Nominal"), 
	New Column("height", numeric, continuous),
	New column("weight", numeric, continuous,));
	
List={"F","M"};
gb=new window("Choice",
	LB1=List Box(List, width(150), maxSelected(5), nlines(1))
);

n=0; 																							
e=10; 																										
startwork = Function( {}, 
dt1=Open( "$sample_data/big class.jmp");

Choice=LB1 << get selected;

dt0 << Concatenate( current data table(), "Append to First Table");

dt0 << Select Where( Contains( Choice, :sex ) );

n+=1;
Close (dt1, nosave);
if(n<e, Schedule(5, startwork() ); ,Schedule( 0, 0)););
startwork();

Many thanks for your responses, I learned very useful commands!

 

 

Article Labels

    There are no labels assigned to this post.