cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
Ksrzg01
Level I

Iterate Through Data Table to Select Matching Items in Another Data Table

Good Morning All,

 

I am trying to create a script which will iterate through two columns on one data table and select all of the matching characters on another data table to perform a simple bivariate graph. To help visualize, consider me trying to iterate through Little Class.JMP by Sex and Name and select all matching rows on Big Class.JMP, then for each iteration, graph height by weight.

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Iterate Through Data Table to Select Matching Items in Another Data Table

Is this what you are thinking of?

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA\big class.jmp" );
dt << select where( Mod( Row(), 3 ) == 0 );
dtlookup = dt << subset( selected columns( 0 ), selected rows( 1 ) );
For( i = 1, i <= N Rows( dtlookup ), i++,
	dt << clear row states;
	dt << select where( dtlookup:name[i] == dt:name & dtlookup:sex == dt:sex );
	dt << invert row selection;
	dt << hide and exclude( 1 );
	biv = Bivariate( Y( :height ), X( :weight ) );
	Report( biv )[Outline Box( 1 )] << set title( dtlookup:name[i] );
);
Jim

View solution in original post

9 REPLIES 9
txnelson
Super User

Re: Iterate Through Data Table to Select Matching Items in Another Data Table

Is this what you are thinking of?

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA\big class.jmp" );
dt << select where( Mod( Row(), 3 ) == 0 );
dtlookup = dt << subset( selected columns( 0 ), selected rows( 1 ) );
For( i = 1, i <= N Rows( dtlookup ), i++,
	dt << clear row states;
	dt << select where( dtlookup:name[i] == dt:name & dtlookup:sex == dt:sex );
	dt << invert row selection;
	dt << hide and exclude( 1 );
	biv = Bivariate( Y( :height ), X( :weight ) );
	Report( biv )[Outline Box( 1 )] << set title( dtlookup:name[i] );
);
Jim
Ksrzg01
Level I

Re: Iterate Through Data Table to Select Matching Items in Another Data Table

This is pretty close to what im looking for. Now imagine I have a column of random ages in another table. I want the script to go down the column of the various ages, subset the ages from the big class DT, and plot the hight by weight. I know I could just do a fit x by y by age but the data set I'm looking at is too large to do this.

txnelson
Super User

Re: Iterate Through Data Table to Select Matching Items in Another Data Table

The code I gave you just needs to be expanded to the logic you described in your response.  You should be able to write that code given the leg up of my example, and access to the Scripting Guide and Scripting Index

     Help==Books==>Scripting Guide

 

     Help==>Scripting Index

 

Jim
Ksrzg01
Level I

Re: Iterate Through Data Table to Select Matching Items in Another Data Table

Thanks for the help Jim! Finally got it all figured out with very little variation to the solution you provided me.

Ksrzg01
Level I

Re: Iterate Through Data Table to Select Matching Items in Another Data Table

Hey, one last thing. How can I save each individual graph to a journal?

txnelson
Super User

Re: Iterate Through Data Table to Select Matching Items in Another Data Table

Here is the example from the Scripting Index on saving to a journal

Names Default To Here( 1 );
//This message applies to all display box objects
Open( "$SAMPLE_DATA/Big Class.jmp" );
biv = bivariate( y( :weight ), x( :height ) );
rbiv = biv << report;
rbiv << Save Journal( "path/to/example.jrn" );
Jim
Ksrzg01
Level I

Re: Iterate Through Data Table to Select Matching Items in Another Data Table

Worked great. Thanks!

jj_jmp
Level II

Re: Iterate Through Data Table to Select Matching Items in Another Data Table

Should it be this? I don't see why name gets [i] but sex does not get [i]

 

 

dt << select where( dtlookup:name[i] == dt:name & dtlookup:sex[i] == dt:sex );

//rather than

dt << select where( dtlookup:name[i] == dt:name & dtlookup:sex == dt:sex );

 

txnelson
Super User

Re: Iterate Through Data Table to Select Matching Items in Another Data Table

You are correct

Jim