<?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: iterate through rows and move data to preceding row of another column in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/iterate-through-rows-and-move-data-to-preceding-row-of-another/m-p/227278#M45096</link>
    <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/706"&gt;@stan_koprowski&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It works perfectly. Thanks a lot.&lt;/P&gt;</description>
    <pubDate>Thu, 26 Sep 2019 02:19:40 GMT</pubDate>
    <dc:creator>redray12</dc:creator>
    <dc:date>2019-09-26T02:19:40Z</dc:date>
    <item>
      <title>iterate through rows and move data to preceding row of another column</title>
      <link>https://community.jmp.com/t5/Discussions/iterate-through-rows-and-move-data-to-preceding-row-of-another/m-p/227015#M45051</link>
      <description>&lt;P&gt;I have very limited coding experience with JSL and can do with some help to solve this problem. Basically, I have alternating rows of when tools are down and up and wanted to transfer/move the up time to a new column under the down time and compute the difference. I have attached two tables--this1 which is current data I have and this2 is the desired output.&lt;/P&gt;&lt;P&gt;Basically, transform from this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="this1.JPG" style="width: 999px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/19456i41BBAF21F33CC435/image-size/large?v=v2&amp;amp;px=999" role="button" title="this1.JPG" alt="this1.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;to this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="this2.JPG" style="width: 999px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/19457i3ACB899530056DFE/image-size/large?v=v2&amp;amp;px=999" role="button" title="this2.JPG" alt="this2.JPG" /&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;Create new columns named: "txn_up_date" and "comment_up"&lt;/P&gt;&lt;P&gt;Loop through the each row and do the following:&lt;/P&gt;&lt;P&gt;Check if the first occurrence of a tool is "Up" under "new_availability" ;&lt;/P&gt;&lt;P&gt;if yes, delete the row and continue the loop&lt;/P&gt;&lt;P&gt;otherwise, check if the same tool has a succeeding row with a "Up" status under "new availability" column&lt;/P&gt;&lt;P&gt;if yes, do the following:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;a. Transfer both the "txn_date" and "comment" of the succeeding row (i.e."Up" in new_availability column) to the preceding row's newly created "txn_up_date" and "comment_up" columns respectively.&lt;/LI&gt;&lt;LI&gt;b. Then keep the preceding role but delete the succeeding one which just got some of its contents transferred. if no; delete the row.&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Wed, 25 Sep 2019 17:56:28 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/iterate-through-rows-and-move-data-to-preceding-row-of-another/m-p/227015#M45051</guid>
      <dc:creator>redray12</dc:creator>
      <dc:date>2019-09-25T17:56:28Z</dc:date>
    </item>
    <item>
      <title>Re: iterate through rows and move data to preceding row of another column</title>
      <link>https://community.jmp.com/t5/Discussions/iterate-through-rows-and-move-data-to-preceding-row-of-another/m-p/227276#M45095</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/16123"&gt;@redray12&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is one way to do this--&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Data Table("this1.jmp");

//Create some new columns
dt&amp;lt;&amp;lt;New Column("Del_Flag", Numeric);
dt&amp;lt;&amp;lt;New Column("txn_date_up", Numeric, Continuous);
:txn_date_up &amp;lt;&amp;lt; Format( "y/m/d h:m:s" ); 

dt &amp;lt;&amp;lt; New Column("comment_up", Character, Nominal);

//Iterate over each row looking for conditions.  When found set new column values
For Each Row(
	If( :entity[] == Lag( :entity[], 1 ) &amp;amp; :new_availability[] != "Down" | Row() == 1,
		:Del_Flag[] = 1,
	    :txn_date_up[Row()] = :txn_date[Row() + 1];
	    :comment_up[Row()] = :comments[Row() + 1];
	)
);

//Clean up the table by deleting rows
dt &amp;lt;&amp;lt; Select Where(:Del_Flag==1 | :new_availability == "Up");
dt &amp;lt;&amp;lt; Delete Rows;

//Remove temporary column
dt:Del_Flag &amp;lt;&amp;lt; Set Selected;
dt &amp;lt;&amp;lt; Delete Columns();&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;cheers,&lt;/P&gt;
&lt;P&gt;Stan&lt;/P&gt;</description>
      <pubDate>Thu, 26 Sep 2019 01:09:37 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/iterate-through-rows-and-move-data-to-preceding-row-of-another/m-p/227276#M45095</guid>
      <dc:creator>stan_koprowski</dc:creator>
      <dc:date>2019-09-26T01:09:37Z</dc:date>
    </item>
    <item>
      <title>Re: iterate through rows and move data to preceding row of another column</title>
      <link>https://community.jmp.com/t5/Discussions/iterate-through-rows-and-move-data-to-preceding-row-of-another/m-p/227278#M45096</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/706"&gt;@stan_koprowski&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It works perfectly. Thanks a lot.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Sep 2019 02:19:40 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/iterate-through-rows-and-move-data-to-preceding-row-of-another/m-p/227278#M45096</guid>
      <dc:creator>redray12</dc:creator>
      <dc:date>2019-09-26T02:19:40Z</dc:date>
    </item>
  </channel>
</rss>

