<?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: Fill rows in main table depending on conditions in second table in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Fill-rows-in-main-table-depending-on-conditions-in-second-table/m-p/454833#M70128</link>
    <description>&lt;P&gt;Here are some suggestions:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;When you do something with JMP, check out the script JMP provides in different locations (red triangle menu, source table script, enhanced log in JMP16+)&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://www.jmp.com/content/dam/jmp/documents/en/support/jmp162/scripting-guide.pdf" target="_blank" rel="noopener"&gt;JMP Scripting Guide&lt;/A&gt; from &lt;A href="https://www.jmp.com/en_us/support/jmp-documentation.html" target="_blank" rel="noopener"&gt;JMP Documentation&lt;/A&gt; (and &lt;A href="https://www.jmp.com/content/dam/jmp/documents/en/support/jmp162/jsl-syntax-reference.pdf" target="_blank" rel="noopener"&gt;JSL Syntax Reference)&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;Scripting Index directly from JMP Help menu&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://www.jmp.com/support/help/en/16.2/?os=win&amp;amp;source=application&amp;amp;utm_source=helpmenu&amp;amp;utm_medium=application#page/jmp/introduction.shtml#" target="_blank" rel="noopener"&gt;Scripting Guide in JMP Help web page&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;Browse JMP Community&lt;/LI&gt;
&lt;LI&gt;Mastering JMP Webinars (some of these might be using old versions of JMP and not the newest possible techniques available), but here is one example: &lt;A href="https://community.jmp.com/t5/Mastering-JMP/Automating-Analyses-Using-JMP-Scripts/ta-p/330245" target="_blank" rel="noopener"&gt;Automating Analyses Using JMP Scripts&lt;/A&gt;&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;There are at least couple of books available: &lt;A href="https://sasinstitute.redshelf.com/book/1878340" target="_blank" rel="noopener"&gt;Jump into JMP Scripting&lt;/A&gt; and &lt;A href="https://sasinstitute.redshelf.com/book/1878402" target="_blank" rel="noopener"&gt; JSL Companion Applications of the JMP Scripting Language, Second Edition&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://community.jmp.com/t5/JMP-Scripting-Users-Group/gh-p/scripting-jug" target="_blank" rel="noopener"&gt;JMP Scripting Users Group&lt;/A&gt; in JMP Community&lt;/LI&gt;
&lt;/UL&gt;</description>
    <pubDate>Wed, 26 Jan 2022 17:27:40 GMT</pubDate>
    <dc:creator>jthi</dc:creator>
    <dc:date>2022-01-26T17:27:40Z</dc:date>
    <item>
      <title>Fill rows in main table depending on conditions in second table</title>
      <link>https://community.jmp.com/t5/Discussions/Fill-rows-in-main-table-depending-on-conditions-in-second-table/m-p/454583#M70095</link>
      <description>&lt;P&gt;I have a&amp;nbsp; main table with timestamp for 2021 in one minute resolution ("Timestamp-1min"). Need to fill the main table with data from second table with one-day resolution ("Start-End-TS1") depending on a pair of conditions for each day in a year(Sunrise, Sunset: Twilight Start and End) while matching the day, month and [time(Hr:min) in the conditions].&lt;/P&gt;&lt;P&gt;I have done it for Date 6/14/2021- which is in the "Timestamp-1min-Result" table.&lt;/P&gt;&lt;P&gt;I added one column -"S Start-S End"- which is Sunrise-Start, Sunrise-End&amp;nbsp; in the same column at the matching times for every day and another column for Twilight(Start and End) likewise. I also want to populate the Day Length, Mid T, Twilight time and a code column (DT/TT)- Daytime/ Twilight time which will help in performing statistics with another table that I would join later. How can I just use formulas to populate the Total day time and Twilight time (In the results table) instead of taking values from the second table. How can I create the code for Daytime alone (as DT) and Twilight time (as TT) alone?&lt;/P&gt;&lt;P&gt;How to do it interactively? OR Is JSL the only way?&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:43:18 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Fill-rows-in-main-table-depending-on-conditions-in-second-table/m-p/454583#M70095</guid>
      <dc:creator>SymS</dc:creator>
      <dc:date>2023-06-10T23:43:18Z</dc:date>
    </item>
    <item>
      <title>Re: Fill rows in main table depending on conditions in second table</title>
      <link>https://community.jmp.com/t5/Discussions/Fill-rows-in-main-table-depending-on-conditions-in-second-table/m-p/454619#M70098</link>
      <description>&lt;P&gt;The only efficient way to do what you want is to use a piece of JSL.&amp;nbsp; Doing it using multiple formula columns would force the reading through a half a million records multiple times.&amp;nbsp; The JSL below reads through the main table only once.&lt;/P&gt;
&lt;P&gt;Also, you could do this all in one table, but then you would have to pretend you are using Excel and move all of the data from the lookup data table into the main table and then hid the columns.&amp;nbsp; It wouldn't be pretty.&amp;nbsp; Here is the script that I think should get you a long way into solving your issue.&amp;nbsp; With a half a million records it takes a few minutes to do all of the required comparisons.&amp;nbsp; Please note, the script is looking for 2 data tables with specific names.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dtMain = Data Table( "Timestamp-1min" );
dtLookUP = Data Table( "Start-End-TS1" );

// Add the required new colummns
dtMain &amp;lt;&amp;lt; New Column( "S Start-S End", format("h:m:s"));
dtMain &amp;lt;&amp;lt; New Column( "T Start-T End", format("h:m:s"));
dtMain &amp;lt;&amp;lt; New Column( "Day Length", format("h:m:s"));
dtMain &amp;lt;&amp;lt; New Column( "Mid T", format("h:m:s"));
dtMain &amp;lt;&amp;lt; New Column( "Twilight time", format("h:m:s"));
dtMain &amp;lt;&amp;lt; New Column( "DT/TT", character);

// Loop through Main table and set values
DT = "";
dl = twTime = .;
For( i = 1, i &amp;lt;= N Rows( dtMain ), i++,
	If( i == 1 | Day( dtMain:Timestamp[i] ) != Day( dtMain:Timestamp[i - 1] ),
		theRow = Try(
			(dtLookUp &amp;lt;&amp;lt; get rows where(
				dtLookUp:Month 2 == Month( dtMain:Timestamp[i] ) &amp;amp; dtLookUp:Date == Day( dtMain:Timestamp[i] )
			))[1],
			.
		)
	);
	
	// Get the time for the current row
	theTime = Date MDY( 12, 31, 1899 ) + 3600 * Hour( dtMain:Timestamp[i] ) + 60 * Minute( dtMain:Timestamp[i] )
	+Second( dtMain:Timestamp[i] );
	theNextTime = Date MDY( 12, 31, 1899 ) + 3600 * Hour( dtMain:Timestamp[i + 1] ) + 60 *
	Minute( dtMain:Timestamp[i + 1] ) + Second( dtMain:Timestamp[i + 1] );
	
	// If this is a Twilight Start, record the time, and set the value for Twilight time
	If( dtLookUp:Twilight start[theRow] &amp;gt;= theTime &amp;amp; dtLookUp:TwilightStart[theRow] &amp;lt;= theNextTime,
		dtMain:"T Start-T End"n[i] = dtLookUp:Twilight start[theRow];
		DT = "TT";
		twTime = dtLookUp:Twilight Length[theRow];
	);
	
	// If this is Sunrise, recorde the time and set the value for Day Length
	If( dtLookUp:Sunrise[theRow] &amp;gt;= theTime &amp;amp; dtLookUp:Sunrise[theRow] &amp;lt;= theNextTime,
		dtMain:"S Start-S End"n[i] = dtLookUp:Sunrise[theRow];
		DT = "DT";
		dl = dtLookUp:Day Length[theRow];
	);
	
	// If sunset has ended record the value and blank out the day length time
	If( dtLookUp:Sunset[theRow] &amp;gt;= theTime &amp;amp; dtLookUp:Sunset[theRow] &amp;lt;= theNextTime,
		dtMain:"S Start-S End"n[i] = dtLookUp:Sunset[theRow];
		DT = "TT";
		dl = .;
	);
	
	// If twighlight has ended record the value and blank out the Twilight time
	If( dtLookUp:Twilight End[theRow] &amp;gt;= theTime &amp;amp; dtLookUp:Twilight End[theRow] &amp;lt;= theNextTime,
		dtMain:"T Start-T End"n[i] = dtLookUp:Twilight End[theRow];
		DT = "";
		twTime = .;
	);
	
	// If this is the Mid T time, record the value 
	If( dtLookUp:Mid T[theRow] &amp;gt;= theTime &amp;amp; dtLookUp:Mid T[theRow] &amp;lt;= theNextTime,
		dtMain:Mid T[i] = dtLookUp:Mid T[theRow]
	);
	
	// Write the repeating values
	dtMain:"DT/TT"n[i] = DT;
	dtMain:Twilight time[i] = twTime;
	dtMain:Day Length[i] = dl;
	
	// Do some cleanup on ending records
	If( Is Missing( dtMain:"S Start-S End"n[i] ) == 0 &amp;amp; Is Missing( dtMain:Day Length[i - 1] ) == 0,
		dtMain:Day Length[i] = dtMain:Day Length[i - 1]
	);
	If( Is Missing( dtMain:"T Start-T End"n[i] ) == 0 &amp;amp; Is Missing( dtMain:Twilight time[i - 1] ) == 0,
		dtMain:Twilight time[i] = dtMain:Twilight time[i - 1]
	);
	If( Is Missing( dtMain:Twilight time[i] ) == 0 &amp;amp; dtMain:"DT/TT"n[i] == "",
		dtMain:"DT/TT"n[i] = dtMain:"DT/TT"n[i - 1]
	);
);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Jan 2022 09:38:59 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Fill-rows-in-main-table-depending-on-conditions-in-second-table/m-p/454619#M70098</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2022-01-26T09:38:59Z</dc:date>
    </item>
    <item>
      <title>Re: Fill rows in main table depending on conditions in second table</title>
      <link>https://community.jmp.com/t5/Discussions/Fill-rows-in-main-table-depending-on-conditions-in-second-table/m-p/454830#M70127</link>
      <description>&lt;P&gt;Nelson,&lt;/P&gt;&lt;P&gt;Amazing! Thanks a lot!!!&lt;/P&gt;&lt;P&gt;Need to know where to start to practice scripting. Are there basic scripting examples which we could follow and DIY?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jan 2022 17:06:32 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Fill-rows-in-main-table-depending-on-conditions-in-second-table/m-p/454830#M70127</guid>
      <dc:creator>SymS</dc:creator>
      <dc:date>2022-01-26T17:06:32Z</dc:date>
    </item>
    <item>
      <title>Re: Fill rows in main table depending on conditions in second table</title>
      <link>https://community.jmp.com/t5/Discussions/Fill-rows-in-main-table-depending-on-conditions-in-second-table/m-p/454833#M70128</link>
      <description>&lt;P&gt;Here are some suggestions:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;When you do something with JMP, check out the script JMP provides in different locations (red triangle menu, source table script, enhanced log in JMP16+)&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://www.jmp.com/content/dam/jmp/documents/en/support/jmp162/scripting-guide.pdf" target="_blank" rel="noopener"&gt;JMP Scripting Guide&lt;/A&gt; from &lt;A href="https://www.jmp.com/en_us/support/jmp-documentation.html" target="_blank" rel="noopener"&gt;JMP Documentation&lt;/A&gt; (and &lt;A href="https://www.jmp.com/content/dam/jmp/documents/en/support/jmp162/jsl-syntax-reference.pdf" target="_blank" rel="noopener"&gt;JSL Syntax Reference)&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;Scripting Index directly from JMP Help menu&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://www.jmp.com/support/help/en/16.2/?os=win&amp;amp;source=application&amp;amp;utm_source=helpmenu&amp;amp;utm_medium=application#page/jmp/introduction.shtml#" target="_blank" rel="noopener"&gt;Scripting Guide in JMP Help web page&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;Browse JMP Community&lt;/LI&gt;
&lt;LI&gt;Mastering JMP Webinars (some of these might be using old versions of JMP and not the newest possible techniques available), but here is one example: &lt;A href="https://community.jmp.com/t5/Mastering-JMP/Automating-Analyses-Using-JMP-Scripts/ta-p/330245" target="_blank" rel="noopener"&gt;Automating Analyses Using JMP Scripts&lt;/A&gt;&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;There are at least couple of books available: &lt;A href="https://sasinstitute.redshelf.com/book/1878340" target="_blank" rel="noopener"&gt;Jump into JMP Scripting&lt;/A&gt; and &lt;A href="https://sasinstitute.redshelf.com/book/1878402" target="_blank" rel="noopener"&gt; JSL Companion Applications of the JMP Scripting Language, Second Edition&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://community.jmp.com/t5/JMP-Scripting-Users-Group/gh-p/scripting-jug" target="_blank" rel="noopener"&gt;JMP Scripting Users Group&lt;/A&gt; in JMP Community&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Wed, 26 Jan 2022 17:27:40 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Fill-rows-in-main-table-depending-on-conditions-in-second-table/m-p/454833#M70128</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2022-01-26T17:27:40Z</dc:date>
    </item>
  </channel>
</rss>

