cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Discussions

Solve problems, and share tips and tricks with other JMP users.
%3CLINGO-SUB%20id%3D%22lingo-sub-59911%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EIt%C3%A9ration%20%C3%A0%20travers%20deux%20tableaux%20de%20donn%C3%A9es%20de%20tailles%20diff%C3%A9rentes%20et%20comparaison%20des%20valeurs%20correspondantes%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-59911%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ESalut%2C%3C%2FP%3E%3CP%3EJ'ai%20le%20probl%C3%A8me%20suivant%20%3A%3C%2FP%3E%3CP%3E-%20J'ai%20deux%20tables%20de%20donn%C3%A9es%20dans%20des%20fichiers%20jmp%20s%C3%A9par%C3%A9s%2C%20chacun%20ayant%20une%20colonne.%3C%2FP%3E%3CP%3E-%20Une%20table%20est%20longue%20de%208%20lignes%20tandis%20que%20l'autre%20est%20longue%20de%206440%20lignes.%3C%2FP%3E%3CP%3E-%20Mon%20objectif%20est%20de%20parcourir%20chacune%20des%20valeurs%20du%20tableau%20%C3%A0%208%20lignes%20et%20de%20les%20comparer%20%C3%A0%20chaque%20valeur%20du%20tableau%20%C3%A0%206440%20lignes%20pour%20voir%20si%20elles%20correspondent.%3C%2FP%3E%3CP%3E-%20Je%20me%20demandais%20simplement%20comment%20je%20pourrais%20faire%20cela%20parce%20que%20je%20veux%20parcourir%20les%20deux%20tables%20mais%20elles%20sont%20de%20tailles%20diff%C3%A9rentes.%20Je%20pensais%20utiliser%20une%20boucle%20for%20imbriqu%C3%A9e%20mais%20je%20ne%20suis%20pas%20trop%20s%C3%BBr.%3C%2FP%3E%3CP%3EToute%20aide%20serait%20appr%C3%A9ci%C3%A9e.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-60227%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%26nbsp%3B%3A%20It%C3%A9rer%20dans%20deux%20tableaux%20de%20donn%C3%A9es%20de%20tailles%20diff%C3%A9rentes%20et%20comparer%20les%20valeurs%20correspondantes%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-60227%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%3CSPAN%3EJ'ai%20fait%20une%20l%C3%A9g%C3%A8re%20erreur%20dans%20mon%20exemple%20de%20pseudo-code%20pr%C3%A9c%C3%A9dent%2C%3C%2FSPAN%3E%3C%2FP%3E%0A%3CPRE%3EdtShort%3ACompare%20Column%5Bi%5D%20%26gt%3B%20dtLong%3ACompare%20Column%3CCODE%20class%3D%22%20language-jsl%22%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%3CSPAN%3EDoit%20%C3%AAtre%20invers%C3%A9%20dans%20la%20logique%20pour%20que%20cela%20fonctionne%3C%2FSPAN%3E%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3E%20dtLong%3ACompare%20Column%20%26gt%3B%20dtShort%3ACompare%20Column%5Bi%5D%20%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%3CSPAN%3EVoici%20un%20exemple%20de%20travail%3C%2FSPAN%3E%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20Default%20To%20Here(%201%20)%3B%0AdtLong%20%3D%20Open(%20%22%24SAMPLE_DATA%2FBig%20Class.jmp%22%20)%3B%0A%2F%2F%20Create%20the%20short%20data%20table%0AdtShort%20%3D%20New%20Table(%20%22Short%22%2C%0A%20New%20Column(%20%22Target%20Age%22%2C%20values(%20%7B12%2C%2016%7D%20)%20)%2C%0A%20New%20Column(%20%22Match%22%2C%20character%2C%20values(%20%7B%22Teenager%22%2C%20%22Young%20Adult%22%7D%20)%20)%0A)%3B%0A%0A%2F%2F%20Sort%20the%20data%20for%20illustration%20of%20data%20not%20being%0A%2F%2F%20in%20age%20order%0AdtLong%20%26lt%3B%26lt%3B%20sort(%20by(%20%3AName%20)%2C%20replace%20table(%201%20)%20)%3B%0A%0A%2F%2F%20Create%20a%20couple%20of%20new%20columns%20in%20the%20data%20table%0AdtLong%20%26lt%3B%26lt%3B%20New%20Column(%20%22Kind%20Of%20Match%22%2C%20character%20)%3B%0AdtLong%20%26lt%3B%26lt%3B%20New%20Column(%20%22Count%22%20)%3B%0A%0A%2F%2F%20Process%20the%20data%0AFor(%20i%20%3D%201%2C%20i%20%26lt%3B%3D%20N%20Rows(%20dtShort%20)%2C%20i%2B%2B%2C%20%0A%20%2F%2F%20Find%20all%20rows%20that%20match%20the%20Where%20Clause%0A%20theRowsFound%20%3D%20dtLong%20%26lt%3B%26lt%3B%20get%20rows%20where(%20dtLong%3AAge%20%26gt%3B%20dtShort%3ATarget%20Age%5Bi%5D%20)%3B%0A%20%2F%2F%20If%20some%20rows%20were%20found%20process%0A%20If(%20N%20Rows(%20theRowsFound%20)%20%26gt%3B%200%2C%20%0A%20%20%2F%2F%20Set%20a%20value%20in%20the%20dtLong%20data%20table%20with%20one%20statement%0A%20%20%2F%2F%20that%20sets%20values%20in%20multiple%20rows%0A%20%20dtLong%3AKind%20Of%20Match%5BtheRowsFound%5D%20%3D%20dtShort%3AMatch%5Bi%5D%3B%0A%20%20%2F%2F%20Now%20set%20values%20row%20by%20row%20for%20individual%20rows%20that%20were%20found%0A%20%20theCount%20%3D%201%3B%0A%20%20For(%20k%20%3D%201%2C%20k%20%26lt%3B%3D%20N%20Items(%20theRowsFound%20)%2C%20K%2B%2B%2C%0A%20%20%20dtLong%3ACount%5BtheRowsFound%5Bk%5D%5D%20%3D%20theCount%3B%0A%20%20%20theCount%20%3D%20theCount%20%2B%201%3B%0A%20%20)%3B%0A%20)%3B%0A)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-60222%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%26nbsp%3B%3A%20It%C3%A9rer%20dans%20deux%20tableaux%20de%20donn%C3%A9es%20de%20tailles%20diff%C3%A9rentes%20et%20comparer%20les%20valeurs%20correspondantes%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-60222%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EMerci%20pour%20la%20r%C3%A9ponse%20rapide.%3C%2FP%3E%3CP%3EPour%20la%20partie%20suivante%20%3A%3C%2FP%3E%3CPRE%3EdtLong%20%3A%20Compare%20Column%20%3C%2FPRE%3E%3CP%3ECela%20vous%20d%C3%A9range-t-il%20d'expliquer%20comment%20je%20pourrais%20acc%C3%A9der%20%C3%A0%20toutes%20les%20valeurs%20d'une%20colonne%20sans%20avoir%20%C3%A0%20faire%20r%C3%A9f%C3%A9rence%20%C3%A0%20chaque%20indice%2Findex%20de%20la%20colonne%26nbsp%3B%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-59922%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%26nbsp%3B%3A%20It%C3%A9rer%20dans%20deux%20tableaux%20de%20donn%C3%A9es%20de%20tailles%20diff%C3%A9rentes%20et%20comparer%20les%20valeurs%20correspondantes%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-59922%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EVoici%20comment%20je%20le%20traiterais%20.......%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3E%2F%2F%20This%20is%20pseudo%20code%2C%20but%20it%20will%20give%20you%20an%20idea%20of%20the%20flow%0A%0AdtShort%20%3D%20Open(%20%22%3CYOUR%20short%3D%22%22%20data%3D%22https%3A%2F%2Fcommunity.jmp.com%2F%22%20table%3D%22%22%3E%22%20)%3B%0AdtLong%20%3D%20Open(%20%22%3CYOUR%20long%3D%22%22%20data%3D%22https%3A%2F%2Fcommunity.jmp.com%2F%22%20table%3D%22%22%3E%22%20)%3B%0A%0AFor(%20i%20%3D%201%2C%20i%20%26lt%3B%3D%20N%20Rows(%20dtShort%20)%2C%20i%2B%2B%2C%0A%20theRowsFound%20%3D%20dtLong%20%26lt%3B%26lt%3B%20get%20rows%20where(%20dtShort%3ACompare%20Column%5Bi%5D%20%26gt%3B%20dtLong%3ACompare%20Column%20)%3B%0A%20If(%20N%20Rows(%20theRowsFound%20)%20%26gt%3B%200%2C%20%0A%20%20%2F%2F%20Do%20your%20processing%0A%20)%3B%0A)%3B%3C%2FYOUR%3E%3C%2FYOUR%3E%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-59914%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%26nbsp%3B%3A%20It%C3%A9rer%20dans%20deux%20tableaux%20de%20donn%C3%A9es%20de%20tailles%20diff%C3%A9rentes%20et%20comparer%20les%20valeurs%20correspondantes%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-59914%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EMerci%20pour%20votre%20r%C3%A9ponse.%3C%2FP%3E%3CP%3EComment%20sugg%C3%A9reriez-vous%20de%20r%C3%A9soudre%20le%20probl%C3%A8me%20si%20je%20voulais%20v%C3%A9rifier%20si%20la%20valeur%20dans%20le%20tableau%20%C3%A0%208%20lignes%20est%3CEM%3E%20plus%20grand%3C%2FEM%3E%20que%20la%20valeur%20de%20la%20table%20de%206440%20lignes%26nbsp%3B%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-59912%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%26nbsp%3B%3A%20It%C3%A9rer%20dans%20deux%20tableaux%20de%20donn%C3%A9es%20de%20tailles%20diff%C3%A9rentes%20et%20comparer%20les%20valeurs%20correspondantes%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-59912%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EJe%20pense%20que%20la%20fa%C3%A7on%20la%20plus%20simple%20de%20proc%C3%A9der%20serait%20de%20laisser%20JMP%20faire%20le%20travail%20pour%20vous.Si%20vous%20joignez%20les%20tables%20dans%20une%20nouvelle%20table%2C%20vous%20pouvez%20demander%20%C3%A0%20JMP%20de%20cr%C3%A9er%20une%20nouvelle%20colonne%20appel%C3%A9e%20Indicateur%20de%20correspondance%2C%20qui%20vous%20indiquera%20si%20une%20correspondance%20a%20%C3%A9t%C3%A9%20trouv%C3%A9e%20ou%20non.%3C%2FP%3E%0A%3CP%3ETableaux%3D%3D%26gt%3BRejoindre%3C%2FP%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
Jaz
Jaz
Level IV

Iterating Through two Data Tables of Different Sizes & Comparing for Matching Values

Hi,

I have the following problem:

- I have two data tables in seperate jmp files, each of which has one column.

- One table is 8 rows long whilst the other is 6440 rows long.

-  My aim is to go through each of the values in the 8-row table and compare them to every value in the 6440-row table to see if they match.

- I was just wondering how I could go about doing this because I want to iterate through both tables but they are different sizes. I was thinking of using a nested for loop but I'm not too sure.

Any help would be appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Iterating Through two Data Tables of Different Sizes & Comparing for Matching Values

I made a slight error in my previous pseudo code example,

dtShort:Compare Column[i] > dtLong:Compare Column

Needs to be reversed in logic for it to work

 dtLong:Compare Column > dtShort:Compare Column[i] 

Here is a working example

Names Default To Here( 1 );
dtLong = Open( "$SAMPLE_DATA/Big Class.jmp" );
// Create the short data table
dtShort = New Table( "Short",
	New Column( "Target Age", values( {12, 16} ) ),
	New Column( "Match", character, values( {"Teenager", "Young Adult"} ) )
);

// Sort the data for illustration of data not being
// in age order
dtLong << sort( by( :Name ), replace table( 1 ) );

// Create a couple of new columns in the data table
dtLong << New Column( "Kind Of Match", character );
dtLong << New Column( "Count" );

// Process the data
For( i = 1, i <= N Rows( dtShort ), i++, 
	// Find all rows that match the Where Clause
	theRowsFound = dtLong << get rows where( dtLong:Age > dtShort:Target Age[i] );
	// If some rows were found process
	If( N Rows( theRowsFound ) > 0, 
		// Set a value in the dtLong data table with one statement
		// that sets values in multiple rows
		dtLong:Kind Of Match[theRowsFound] = dtShort:Match[i];
		// Now set values row by row for individual rows that were found
		theCount = 1;
		For( k = 1, k <= N Items( theRowsFound ), K++,
			dtLong:Count[theRowsFound[k]] = theCount;
			theCount = theCount + 1;
		);
	);
);
Jim

View solution in original post

5 REPLIES 5
txnelson
Super User

Re: Iterating Through two Data Tables of Different Sizes & Comparing for Matching Values

I believe the easiest way to do this would be to let JMP do the work for you.  If you Join the tables into a new table, you can have JMP create a new column called Match flag, which will tell you if a match was found or not

     Tables==>Join

Jim
Jaz
Jaz
Level IV

Re: Iterating Through two Data Tables of Different Sizes & Comparing for Matching Values

Thanks for your reply.

How would you suggest going about the problem if I wanted to check if the value in the 8-row table is greater than the value in the 6440-row table?

txnelson
Super User

Re: Iterating Through two Data Tables of Different Sizes & Comparing for Matching Values

Here is how I would process it.......

// This is pseudo code, but it will give you an idea of the flow

dtShort = Open( "<your short data table>" );
dtLong = Open( "<your long data table>" );

For( i = 1, i <= N Rows( dtShort ), i++,
	theRowsFound = dtLong << get rows where( dtShort:Compare Column[i] > dtLong:Compare Column );
	If( N Rows( theRowsFound ) > 0, 
		// Do your processing
	);
);
Jim
Jaz
Jaz
Level IV

Re: Iterating Through two Data Tables of Different Sizes & Comparing for Matching Values

Thanks for the quick reply. 

For the following part: 

dtLong : Compare Column 

Do you mind explaining how I could access all the values in a column without having to reference to each subscript/index of the column? 

txnelson
Super User

Re: Iterating Through two Data Tables of Different Sizes & Comparing for Matching Values

I made a slight error in my previous pseudo code example,

dtShort:Compare Column[i] > dtLong:Compare Column

Needs to be reversed in logic for it to work

 dtLong:Compare Column > dtShort:Compare Column[i] 

Here is a working example

Names Default To Here( 1 );
dtLong = Open( "$SAMPLE_DATA/Big Class.jmp" );
// Create the short data table
dtShort = New Table( "Short",
	New Column( "Target Age", values( {12, 16} ) ),
	New Column( "Match", character, values( {"Teenager", "Young Adult"} ) )
);

// Sort the data for illustration of data not being
// in age order
dtLong << sort( by( :Name ), replace table( 1 ) );

// Create a couple of new columns in the data table
dtLong << New Column( "Kind Of Match", character );
dtLong << New Column( "Count" );

// Process the data
For( i = 1, i <= N Rows( dtShort ), i++, 
	// Find all rows that match the Where Clause
	theRowsFound = dtLong << get rows where( dtLong:Age > dtShort:Target Age[i] );
	// If some rows were found process
	If( N Rows( theRowsFound ) > 0, 
		// Set a value in the dtLong data table with one statement
		// that sets values in multiple rows
		dtLong:Kind Of Match[theRowsFound] = dtShort:Match[i];
		// Now set values row by row for individual rows that were found
		theCount = 1;
		For( k = 1, k <= N Items( theRowsFound ), K++,
			dtLong:Count[theRowsFound[k]] = theCount;
			theCount = theCount + 1;
		);
	);
);
Jim

Recommended Articles