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

Community Trekker

Joined:

May 26, 2017

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

Super User

Joined:

Jun 22, 2012

Solution

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 7 REPLIES Super User Joined: Jun 22, 2012 Solution 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

Community Trekker

Joined:

May 26, 2017

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.

Super User

Joined:

Jun 22, 2012

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

Community Trekker

Joined:

May 26, 2017

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

Community Trekker

Joined:

May 26, 2017

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

Super User

Joined:

Jun 22, 2012

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

Community Trekker

Joined:

May 26, 2017

Worked great. Thanks!