<?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: How do I create a new column and insert a text x-rows before an 'event' and y-rows after the 'event' in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-do-I-create-a-new-column-and-insert-a-text-x-rows-before-an/m-p/246640#M48422</link>
    <description>Excellent, many thanks Jim!</description>
    <pubDate>Sun, 09 Feb 2020 17:07:50 GMT</pubDate>
    <dc:creator>WernerL</dc:creator>
    <dc:date>2020-02-09T17:07:50Z</dc:date>
    <item>
      <title>How do I create a new column and insert a text x-rows before an 'event' and y-rows after the 'event'</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-create-a-new-column-and-insert-a-text-x-rows-before-an/m-p/246357#M48386</link>
      <description>&lt;P&gt;Hi JMP Community, I am working with a table with thousands of rows. In one column certain rows are marked 'event' (e.g. an out-of-spec lot on a particular day). How can I create a new column where the x rows before an 'event' are marker PRE and the y rows after the event are marked POST. In the example below x=3 and y=5.&lt;/P&gt;&lt;P&gt;Thank you for your help!&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="WernerL_0-1581077503342.png" style="width: 164px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/21626i6DB1AEE0B78C842F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="WernerL_0-1581077503342.png" alt="WernerL_0-1581077503342.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2020 12:14:12 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-create-a-new-column-and-insert-a-text-x-rows-before-an/m-p/246357#M48386</guid>
      <dc:creator>WernerL</dc:creator>
      <dc:date>2020-02-07T12:14:12Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a new column and insert a text x-rows before an 'event' and y-rows after the 'event'</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-create-a-new-column-and-insert-a-text-x-rows-before-an/m-p/246461#M48400</link>
      <description>&lt;P&gt;It's not clear from your example when the next "PRE" should start.&amp;nbsp; Can you provide a small example dataset?&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2020 16:19:21 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-create-a-new-column-and-insert-a-text-x-rows-before-an/m-p/246461#M48400</guid>
      <dc:creator>pmroz</dc:creator>
      <dc:date>2020-02-07T16:19:21Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a new column and insert a text x-rows before an 'event' and y-rows after the 'event'</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-create-a-new-column-and-insert-a-text-x-rows-before-an/m-p/246465#M48402</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/4550"&gt;@pmroz&lt;/a&gt;&amp;nbsp;&amp;nbsp;Please find attached brief example.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Each 'PRE' should start (in this example) 3 rows before the 'Event'-row and stop 1 row before the 'Event'&lt;/P&gt;&lt;P&gt;Each 'POST' should start 1 row after the event and stop 5 rows after the 'Event'&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2020 16:36:49 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-create-a-new-column-and-insert-a-text-x-rows-before-an/m-p/246465#M48402</guid>
      <dc:creator>WernerL</dc:creator>
      <dc:date>2020-02-07T16:36:49Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a new column and insert a text x-rows before an 'event' and y-rows after the 'event'</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-create-a-new-column-and-insert-a-text-x-rows-before-an/m-p/246474#M48403</link>
      <description>&lt;P&gt;This should do it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;/* Each 'PRE' should start (in this example) 3 rows before the 'Event'-row and 
stop 1 row before the 'Event'
Each 'POST' should start 1 row after the event and stop 5 rows after the 'Event'
Thank you! */
dt = New Table( "pre-post example", Add Rows( 23 ),
	New Column( "Column 1", Character, "Nominal",
		Set Values(
			{"", "", "", "", "Event", "", "", "", "", "", "", "", "", "", "", "", "",
			"Event", "", "", "", "", ""}
		)
	),
	New Column( "Column 2", Character, "Nominal",
		Set Values(
			{"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
			"", "", "", "", ""}
		)
	)
);

event_rows = dt &amp;lt;&amp;lt; get rows where(dt:Column 1 == "Event");
nr = nrows(event_rows);
if (nr &amp;gt; 0,
	for (i = 1, i &amp;lt;= nr, i++,
		start_row = maximum(event_rows[i] - 3, 1);	// Keep from trying to set a negative row
		for (k = start_row, k &amp;lt; event_rows[i] , k++,
			dt:column 2[k] = "PRE";
		);
		end_row = minimum(event_rows[i] + 5, nrows(dt));	// Prevent setting higher rows than are in the table
		for (k = event_rows[i] + 1, k &amp;lt;= end_row, k++,
			dt:column 2[k] = "POST";
		);
		dt:column 2[event_rows[i]] = "Event";
	);
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Feb 2020 16:58:02 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-create-a-new-column-and-insert-a-text-x-rows-before-an/m-p/246474#M48403</guid>
      <dc:creator>pmroz</dc:creator>
      <dc:date>2020-02-07T16:58:02Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a new column and insert a text x-rows before an 'event' and y-rows after the 'event'</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-create-a-new-column-and-insert-a-text-x-rows-before-an/m-p/246482#M48404</link>
      <description>&lt;P&gt;Here is a formula that is a real brut force method.&amp;nbsp; It looks more complex than it really is, because of your choice of having a minus sign "-" as part of the column name, forces the code to use the :Name() function around the column name.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If(
	:Name( "Column 1 -Existing" )[Row() + 1] == "Event" |
	:Name( "Column 1 -Existing" )[Row() + 2] == "Event" |
	:Name( "Column 1 -Existing" )[Row() + 3] == "Event", "PRE",
	:Name( "Column 1 -Existing" )[Row() - 1] == "Event" |
	:Name( "Column 1 -Existing" )[Row() - 2] == "Event" |
	:Name( "Column 1 -Existing" )[Row() - 3] == "Event" |
	:Name( "Column 1 -Existing" )[Row() - 4] == "Event" |
	:Name( "Column 1 -Existing" )[Row() - 5] == "Event", "POST",
	:Name( "Column 1 -Existing" )[Row()] == "Event", "Event"
)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Attached is your sample data table with the new column added&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2020 17:19:09 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-create-a-new-column-and-insert-a-text-x-rows-before-an/m-p/246482#M48404</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2020-02-07T17:19:09Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a new column and insert a text x-rows before an 'event' and y-rows after the 'event'</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-create-a-new-column-and-insert-a-text-x-rows-before-an/m-p/246628#M48417</link>
      <description>&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/4550"&gt;@pmroz&lt;/a&gt;, I tried to run your proposed solution, but it creates multiple new tables? (instead of one new column, in the existing table)</description>
      <pubDate>Sun, 09 Feb 2020 13:58:20 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-create-a-new-column-and-insert-a-text-x-rows-before-an/m-p/246628#M48417</guid>
      <dc:creator>WernerL</dc:creator>
      <dc:date>2020-02-09T13:58:20Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a new column and insert a text x-rows before an 'event' and y-rows after the 'event'</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-create-a-new-column-and-insert-a-text-x-rows-before-an/m-p/246631#M48419</link>
      <description>&lt;P&gt;Dear Jim (&lt;A href="https://community.jmp.com/t5/user/viewprofilepage/user-id/2687" target="_blank" rel="noopener"&gt;@ txnelson&lt;/A&gt;&amp;nbsp;) ,&lt;/P&gt;&lt;P&gt;Thank you for offering this solution, which does exactly what I was asking.&lt;/P&gt;&lt;P&gt;Playing around with it, I learned that I overlooked one challenge in my original question: when 'Event'-s come too close after each other, below rules may overwrite previous outcomes.&lt;/P&gt;&lt;P&gt;Is there a way to further fine-tune your solution by embedding following prioritization rules:&lt;/P&gt;&lt;P&gt;- 1st priority: An 'Event' row, always copy in the new column as an 'Event' row and cannot be overwritten by 'POST' or 'PRE';&lt;/P&gt;&lt;P&gt;- 2nd priority: A 'POST' outcome can never be overwritten by a 'PRE'&lt;/P&gt;</description>
      <pubDate>Sun, 09 Feb 2020 14:09:49 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-create-a-new-column-and-insert-a-text-x-rows-before-an/m-p/246631#M48419</guid>
      <dc:creator>WernerL</dc:creator>
      <dc:date>2020-02-09T14:09:49Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a new column and insert a text x-rows before an 'event' and y-rows after the 'event'</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-create-a-new-column-and-insert-a-text-x-rows-before-an/m-p/246632#M48420</link>
      <description>&lt;P&gt;A little adjustment for your additional logic and the following JSL I believe gives you what you want&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If(
	:Name( "Column 1 -Existing" )[Row()] == "Event", "Event",
	(:Name( "Column 1 -Existing" )[Row() - 1] == "Event" |
	:Name( "Column 1 -Existing" )[Row() - 2] == "Event" |
	:Name( "Column 1 -Existing" )[Row() - 3] == "Event" |
	:Name( "Column 1 -Existing" )[Row() - 4] == "Event" |
	:Name( "Column 1 -Existing" )[Row() - 5] == "Event") &amp;amp;
	:Name( "Column 1 -Existing" )[Row()] == "", "POST",
	(:Name( "Column 1 -Existing" )[Row() + 1] == "Event" |
	:Name( "Column 1 -Existing" )[Row() + 2] == "Event" |
	:Name( "Column 1 -Existing" )[Row() + 3] == "Event") &amp;amp;
	:Name( "Column 1 -Existing" )[Row()] == "", "PRE"
)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 09 Feb 2020 15:20:30 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-create-a-new-column-and-insert-a-text-x-rows-before-an/m-p/246632#M48420</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2020-02-09T15:20:30Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a new column and insert a text x-rows before an 'event' and y-rows after the 'event'</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-create-a-new-column-and-insert-a-text-x-rows-before-an/m-p/246640#M48422</link>
      <description>Excellent, many thanks Jim!</description>
      <pubDate>Sun, 09 Feb 2020 17:07:50 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-create-a-new-column-and-insert-a-text-x-rows-before-an/m-p/246640#M48422</guid>
      <dc:creator>WernerL</dc:creator>
      <dc:date>2020-02-09T17:07:50Z</dc:date>
    </item>
  </channel>
</rss>

