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%3E%E8%BF%AD%E4%BB%A3%E5%85%A9%E5%80%8B%E4%B8%8D%E5%90%8C%E5%A4%A7%E5%B0%8F%E7%9A%84%E6%95%B8%E6%93%9A%E8%A1%A8%E4%B8%A6%E6%AF%94%E8%BC%83%E5%8C%B9%E9%85%8D%E5%80%BC%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-59911%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%E5%97%A8%EF%BC%8C%3C%2FP%3E%3CP%3E%E6%88%91%E6%9C%89%E4%BB%A5%E4%B8%8B%E5%95%8F%E9%A1%8C%EF%BC%9A%3C%2FP%3E%3CP%3E-%20%E6%88%91%E5%9C%A8%E5%96%AE%E7%8D%A8%E7%9A%84jmp%E6%96%87%E4%BB%B6%E4%B8%AD%E6%9C%89%E5%85%A9%E5%80%8B%E6%95%B8%E6%93%9A%E8%A1%A8%EF%BC%8C%E6%AF%8F%E5%80%8B%E6%96%87%E4%BB%B6%E9%83%BD%E6%9C%89%E4%B8%80%E5%88%97%E3%80%82%3C%2FP%3E%3CP%3E-%20%E4%B8%80%E5%BC%B5%E6%A1%8C%E5%AD%90%E6%98%AF8%E6%8E%92%E9%95%B7%EF%BC%8C%E8%80%8C%E5%8F%A6%E4%B8%80%E5%BC%B5%E6%A1%8C%E5%AD%90%E6%98%AF6440%E6%8E%92%E9%95%B7%E3%80%82%3C%2FP%3E%3CP%3E-%20%E6%88%91%E7%9A%84%E7%9B%AE%E6%A8%99%E6%98%AF%E9%81%8D%E6%AD%B78%E8%A1%8C%E8%A1%A8%E4%B8%AD%E7%9A%84%E6%AF%8F%E5%80%8B%E5%80%BC%EF%BC%8C%E4%B8%A6%E5%B0%87%E5%AE%83%E5%80%91%E8%88%876440%E8%A1%8C%E8%A1%A8%E4%B8%AD%E7%9A%84%E6%AF%8F%E5%80%8B%E5%80%BC%E9%80%B2%E8%A1%8C%E6%AF%94%E8%BC%83%EF%BC%8C%E7%9C%8B%E5%AE%83%E5%80%91%E6%98%AF%E5%90%A6%E5%8C%B9%E9%85%8D%E3%80%82%3C%2FP%3E%3CP%3E-%20%E6%88%91%E5%8F%AA%E6%98%AF%E6%83%B3%E7%9F%A5%E9%81%93%E5%A6%82%E4%BD%95%E5%81%9A%E5%88%B0%E9%80%99%E4%B8%80%E9%BB%9E%EF%BC%8C%E5%9B%A0%E7%82%BA%E6%88%91%E6%83%B3%E8%BF%AD%E4%BB%A3%E5%85%A9%E5%80%8B%E8%A1%A8%EF%BC%8C%E4%BD%86%E5%AE%83%E5%80%91%E6%98%AF%E4%B8%8D%E5%90%8C%E7%9A%84%E5%A4%A7%E5%B0%8F%E3%80%82%E6%88%91%E6%AD%A3%E5%9C%A8%E8%80%83%E6%85%AE%E4%BD%BF%E7%94%A8%E5%B5%8C%E5%A5%97%E7%9A%84for%E5%BE%AA%E7%92%B0%EF%BC%8C%E4%BD%86%E6%88%91%E4%B8%8D%E5%A4%AA%E7%A2%BA%E5%AE%9A%E3%80%82%3C%2FP%3E%3CP%3E%E4%BB%BB%E4%BD%95%E5%B9%AB%E5%8A%A9%EF%BC%8C%E5%B0%87%E4%B8%8D%E5%8B%9D%E6%84%9F%E6%BF%80%E3%80%82%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%EF%BC%9A%E8%BF%AD%E4%BB%A3%E5%85%A9%E5%80%8B%E4%B8%8D%E5%90%8C%E5%A4%A7%E5%B0%8F%E7%9A%84%E6%95%B8%E6%93%9A%E8%A1%A8%E4%B8%A6%E6%AF%94%E8%BC%83%E5%8C%B9%E9%85%8D%E5%80%BC%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%3E%E6%88%91%E5%9C%A8%E4%B9%8B%E5%89%8D%E7%9A%84%E5%81%BD%E4%BB%A3%E7%A2%BC%E7%A4%BA%E4%BE%8B%E4%B8%AD%E7%95%A5%E6%9C%89%E9%8C%AF%E8%AA%A4%EF%BC%8C%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%3E%E9%9C%80%E8%A6%81%E5%9C%A8%E9%82%8F%E8%BC%AF%E4%B8%8A%E9%A1%9B%E5%80%92%E6%89%8D%E8%83%BD%E7%99%BC%E6%8F%AE%E4%BD%9C%E7%94%A8%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%3E%E9%80%99%E6%98%AF%E4%B8%80%E5%80%8B%E6%9C%89%E6%95%88%E7%9A%84%E4%BE%8B%E5%AD%90%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%EF%BC%9A%E8%BF%AD%E4%BB%A3%E5%85%A9%E5%80%8B%E4%B8%8D%E5%90%8C%E5%A4%A7%E5%B0%8F%E7%9A%84%E6%95%B8%E6%93%9A%E8%A1%A8%E4%B8%A6%E6%AF%94%E8%BC%83%E5%8C%B9%E9%85%8D%E5%80%BC%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-60222%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%E6%84%9F%E8%AC%9D%E6%82%A8%E7%9A%84%E5%BF%AB%E9%80%9F%E7%AD%94%E5%A4%8D%E3%80%82%26nbsp%3B%3C%2FP%3E%3CP%3E%E5%B0%8D%E6%96%BC%E4%BB%A5%E4%B8%8B%E9%83%A8%E5%88%86%EF%BC%9A%26nbsp%3B%3C%2FP%3E%3CPRE%3EdtLong%20%3A%20Compare%20Column%20%3C%2FPRE%3E%3CP%3E%E4%BD%A0%E6%98%AF%E5%90%A6%E4%BB%8B%E6%84%8F%E8%A7%A3%E9%87%8B%E5%A6%82%E4%BD%95%E8%A8%AA%E5%95%8F%E5%88%97%E4%B8%AD%E7%9A%84%E6%89%80%E6%9C%89%E5%80%BC%E8%80%8C%E4%B8%8D%E5%BF%85%E5%BC%95%E7%94%A8%E5%88%97%E7%9A%84%E6%AF%8F%E5%80%8B%E4%B8%8B%E6%A8%99%2F%E7%B4%A2%E5%BC%95%EF%BC%9F%26nbsp%3B%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%EF%BC%9A%E8%BF%AD%E4%BB%A3%E5%85%A9%E5%80%8B%E4%B8%8D%E5%90%8C%E5%A4%A7%E5%B0%8F%E7%9A%84%E6%95%B8%E6%93%9A%E8%A1%A8%E4%B8%A6%E6%AF%94%E8%BC%83%E5%8C%B9%E9%85%8D%E5%80%BC%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-59922%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%E9%80%99%E6%98%AF%E6%88%91%E5%A6%82%E4%BD%95%E8%99%95%E7%90%86%E5%AE%83......%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%EF%BC%9A%E8%BF%AD%E4%BB%A3%E5%85%A9%E5%80%8B%E4%B8%8D%E5%90%8C%E5%A4%A7%E5%B0%8F%E7%9A%84%E6%95%B8%E6%93%9A%E8%A1%A8%E4%B8%A6%E6%AF%94%E8%BC%83%E5%8C%B9%E9%85%8D%E5%80%BC%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-59914%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%E6%84%9F%E8%AC%9D%E6%82%A8%E7%9A%84%E5%9B%9E%E5%A4%8D%E3%80%82%3C%2FP%3E%3CP%3E%E5%A6%82%E6%9E%9C%E6%88%91%E6%83%B3%E6%AA%A2%E6%9F%A58%E8%A1%8C%E8%A1%A8%E4%B8%AD%E7%9A%84%E5%80%BC%E6%98%AF%E4%BB%80%E9%BA%BC%EF%BC%8C%E4%BD%A0%E6%9C%83%E5%A6%82%E4%BD%95%E5%BB%BA%E8%AD%B0%E8%A7%A3%E6%B1%BA%E5%95%8F%E9%A1%8C%EF%BC%9F%3CEM%3E%E6%9B%B4%E5%A4%A7%3C%2FEM%3E%E6%AF%946440%E8%A1%8C%E8%A1%A8%E4%B8%AD%E7%9A%84%E5%80%BC%EF%BC%9F%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%EF%BC%9A%E8%BF%AD%E4%BB%A3%E5%85%A9%E5%80%8B%E4%B8%8D%E5%90%8C%E5%A4%A7%E5%B0%8F%E7%9A%84%E6%95%B8%E6%93%9A%E8%A1%A8%E4%B8%A6%E6%AF%94%E8%BC%83%E5%8C%B9%E9%85%8D%E5%80%BC%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-59912%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%E6%88%91%E8%AA%8D%E7%82%BA%E6%9C%80%E7%B0%A1%E5%96%AE%E7%9A%84%E6%96%B9%E6%B3%95%E6%98%AF%E8%AE%93JMP%E7%82%BA%E4%BD%A0%E5%B7%A5%E4%BD%9C%E3%80%82%26nbsp%3B%20%E5%A6%82%E6%9E%9C%E5%B0%87%E8%A1%A8%E9%80%A3%E6%8E%A5%E5%88%B0%E6%96%B0%E8%A1%A8%E4%B8%AD%EF%BC%8C%E5%8F%AF%E4%BB%A5%E8%AE%93JMP%E5%89%B5%E5%BB%BA%E4%B8%80%E5%80%8B%E5%90%8D%E7%82%BAMatch%20flag%E7%9A%84%E6%96%B0%E5%88%97%EF%BC%8C%E5%AE%83%E5%B0%87%E5%91%8A%E8%A8%B4%E6%82%A8%E6%98%AF%E5%90%A6%E6%89%BE%E5%88%B0%E5%8C%B9%E9%85%8D%E9%A0%85%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%E8%A1%A8%3D%3D%26gt%3B%E5%8A%A0%E5%85%A5%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