<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Compare two tables and retreive relevant rows from one table based on the other. in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Compare-two-tables-and-retreive-relevant-rows-from-one-table/m-p/401908#M65282</link>
    <description>I am not finding your description of your  data tables clear enough to allow me to see exactly what their structures are.  Could you please provide a few sample rows and columns for each of the data tables.  That would really be helpful.</description>
    <pubDate>Sun, 18 Jul 2021 07:30:38 GMT</pubDate>
    <dc:creator>txnelson</dc:creator>
    <dc:date>2021-07-18T07:30:38Z</dc:date>
    <item>
      <title>Compare two tables and retreive relevant rows from one table based on the other.</title>
      <link>https://community.jmp.com/t5/Discussions/Compare-two-tables-and-retreive-relevant-rows-from-one-table/m-p/401891#M65281</link>
      <description>&lt;P&gt;I have 2 tables.&lt;/P&gt;&lt;P&gt;Table 1:&amp;nbsp; Timestamp (in 15 minute intervals),i1,i2,i3,p1,p2,p3,p4,.... (182 columns)&lt;/P&gt;&lt;P&gt;Table 2: Year, Month, Date, StartTime, EndTime ( StartTime and EndTime is in the format- h:m am/pm)&lt;/P&gt;&lt;P&gt;I would like to select all 182 columns and only the rows in Table1 which lies between StartTime and EndTime of Table2 and make a subset.&lt;/P&gt;&lt;P&gt;Note:StartTime and EndTime for every date in Table2 could lie anywhere-does not exactly match the Timestamp in Table1.(or in other words StartTime and EndTime is not a multiple of 15)&lt;/P&gt;&lt;P&gt;How can I accomplish this 1) using point and click method- Like Joins and using "Row-Select where". or other inbuilt formulas...step by step and 2) JSL&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:34:02 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Compare-two-tables-and-retreive-relevant-rows-from-one-table/m-p/401891#M65281</guid>
      <dc:creator>SymS</dc:creator>
      <dc:date>2023-06-10T23:34:02Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two tables and retreive relevant rows from one table based on the other.</title>
      <link>https://community.jmp.com/t5/Discussions/Compare-two-tables-and-retreive-relevant-rows-from-one-table/m-p/401908#M65282</link>
      <description>I am not finding your description of your  data tables clear enough to allow me to see exactly what their structures are.  Could you please provide a few sample rows and columns for each of the data tables.  That would really be helpful.</description>
      <pubDate>Sun, 18 Jul 2021 07:30:38 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Compare-two-tables-and-retreive-relevant-rows-from-one-table/m-p/401908#M65282</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-07-18T07:30:38Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two tables and retreive relevant rows from one table based on the other.</title>
      <link>https://community.jmp.com/t5/Discussions/Compare-two-tables-and-retreive-relevant-rows-from-one-table/m-p/402207#M65305</link>
      <description>&lt;P&gt;Table 1: Like this I have 15 minute interval data for the whole year.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="SunnyRS_0-1626726235745.png" style="width: 654px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/34336iEEBF0D74D3D78583/image-dimensions/654x126?v=v2" width="654" height="126" role="button" title="SunnyRS_0-1626726235745.png" alt="SunnyRS_0-1626726235745.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table 2: Some times this table has all the dates in the month. Here in the sample there is just a few in each month.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SunnyRS_1-1626727701316.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/34337i7241C0A6A5CD1EF1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SunnyRS_1-1626727701316.png" alt="SunnyRS_1-1626727701316.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Jim, Let me know if this is helpful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jul 2021 20:53:22 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Compare-two-tables-and-retreive-relevant-rows-from-one-table/m-p/402207#M65305</guid>
      <dc:creator>SymS</dc:creator>
      <dc:date>2021-07-19T20:53:22Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two tables and retreive relevant rows from one table based on the other.</title>
      <link>https://community.jmp.com/t5/Discussions/Compare-two-tables-and-retreive-relevant-rows-from-one-table/m-p/402309#M65314</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I understand your question, this would be well beyond agonizing to perform interactively. I take it that you want a subset of the original table, where a row is part of the subset as long as it falls between the begin and end time of ANY row in the begin/end table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If that is what you would like, the script below will do it. It relies on the evalinsert( ) function to build a string in a legitimate date/time format that JMP can convert to a number natively using the informat( ) command... so be sure to check out these 2 functions in the scripting index.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By default, select where ( ) pre-clears any current row selection. The optional argument current selection ("extend") allows us to select additional rows without losing the prior selection--this allows us to use a loop to make selections incrementally.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;Brady&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

////////////////////Build example tables
dt = astable(J(1000,1,randomuniform(today()-3600*24*60, today() + 3600*24*60)), &amp;lt;&amp;lt; column names({"Timestamp"}));
dt:Timestamp &amp;lt;&amp;lt; Input Format( "ddMonyyyy h:m:s", 0 ) &amp;lt;&amp;lt; Format( "ddMonyyyy h:m:s", 22, 0 );
dt &amp;lt;&amp;lt; Sort( By( :Timestamp ), Replace Table, Order( Ascending ) );

yearMat = J(20,1,2021);
monList = words("May,Jun,Jul,Aug,Sep",",")[J(20,1,randominteger(1,5))];
dayMat = J(20,1,randominteger(1,30));
amMat = J(20,1,7*3600 + randominteger(0,20)*60);
pmMat = J(20,1,16*3600 + randominteger(0,20)*60);
dt2 = new table("lookups",
	&amp;lt;&amp;lt;new column("Year", &amp;lt;&amp;lt;set values(yearMat)),
	&amp;lt;&amp;lt;new column("Month", character, &amp;lt;&amp;lt;set values(monList)),
	&amp;lt;&amp;lt;new column("Day", &amp;lt;&amp;lt;set values(dayMat)),
	&amp;lt;&amp;lt;new column("Start", &amp;lt;&amp;lt;set values(amMat), Input Format( "h:m" ), Format( "h:m", 10 )),
	&amp;lt;&amp;lt;new column("End", &amp;lt;&amp;lt;set values(pmMat), Input Format( "h:m" ), Format( "h:m", 10 ))
);

//////////////////////////////end table building


//begin processing. the idea is to cycle through all rows of the lookup table, 
//selecting matching rows in the original table
dt &amp;lt;&amp;lt; clear select;

for(r = 1, r&amp;lt;= nrow(dt2), r++,

	//piece together beginning and ending date/time strings using evalinsert(), 
	//and use informat() to convert to a numeric value
	begin_time = informat(evalinsert("^dt2:day[r]^^dt2:month[r]^^dt2:year[r]^ ^format(dt2:Start[r], \!"h:m\!")^"));
	end_time = informat(evalinsert("^dt2:day[r]^^dt2:month[r]^^dt2:year[r]^ ^format(dt2:End[r], \!"h:m\!")^"));

	//select cells in the main table with a timestamp in this range. 
	//the current selection ("extend") option augments the current selection, instead of replacing it (the default behavior)
	dt &amp;lt;&amp;lt; select where (begin_time &amp;lt;= :timeStamp &amp;lt; end_time, current selection("extend"));
);

dtSub = dt &amp;lt;&amp;lt; subset(selected rows(1), selected columns(0));

dt &amp;lt;&amp;lt; clear select;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Jul 2021 01:47:20 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Compare-two-tables-and-retreive-relevant-rows-from-one-table/m-p/402309#M65314</guid>
      <dc:creator>brady_brady</dc:creator>
      <dc:date>2021-07-20T01:47:20Z</dc:date>
    </item>
  </channel>
</rss>

