It’s World Statistics Day! To honor the theme of the day, the JMP User Community is having conversations about the importance of trust in statistics and data. And we want to hear from you! Tell us the steps you take to ensure that your data is trustworthy.
Choose Language Hide Translation Bar
Highlighted
EDW
EDW
Level I

Selecting Data from Different Tables

I have two data tables, dt1 and dt2, and I am trying to use the function, "For Each Row", to parse through dt1, then within that loop evaluate corresponding data in dt2.In order to make sure a line of code is grabbing data from the right table, do I have to precede it with "Current Data Table (dt1 / dt2)" or the send operator, "<<"? Let me provide a sample block of code and allow you to tweak as necessary.

row_count = 1;
For Each Row (
	item_of_interest = dt1[row_count,1]; //Grab the value in the first column
	dt2 << If ( Contains ( dt2[0,1], item_of_interest), //Look through column 1 in dt2 for that specified value in dt1
		Write("Yes\!n"),
		Write("No\!n");
	);
	row_count++;
);

Thank you!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
txnelson
Super User

Re: Selecting Data from Different Tables

Here is the syntax of how I typically do what you are looking for:

Names default to here(1);
dt1=data table(?????);
dt2=data table(?????);

For( i = 1, i <= N Rows( dt1 ), i++,
	item_of_interest = Column( dt1, 1 )[i]; //Grab the value in the first column
	theRows = dt2 << get rows where( Column( dt1, 1 ) == item_of_interest );
	If( N Rows( theRows ) > 0, //Look through column 1 in dt2 for that specified value in dt1
		Write( "Yes\!n" )
	,
		Write( "No\!n" )
	);
);
Jim

View solution in original post

1 REPLY 1
Highlighted
txnelson
Super User

Re: Selecting Data from Different Tables

Here is the syntax of how I typically do what you are looking for:

Names default to here(1);
dt1=data table(?????);
dt2=data table(?????);

For( i = 1, i <= N Rows( dt1 ), i++,
	item_of_interest = Column( dt1, 1 )[i]; //Grab the value in the first column
	theRows = dt2 << get rows where( Column( dt1, 1 ) == item_of_interest );
	If( N Rows( theRows ) > 0, //Look through column 1 in dt2 for that specified value in dt1
		Write( "Yes\!n" )
	,
		Write( "No\!n" )
	);
);
Jim

View solution in original post

Article Labels

    There are no labels assigned to this post.