<?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: add rows based on a column values in the same data table in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/add-rows-based-on-a-column-values-in-the-same-data-table/m-p/37726#M22120</link>
    <description>&lt;P&gt;I'm not sure if I have understood correctly, but here's an alternative. If it's what you want, you also need to see how well it will scale.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;NamesDefaultToHere(1);

// Example table . . .
dt = New Table( "Inspection",
					Add Rows( 10 ),
					New Column( "ID",
						Character,
						"Nominal",
						Set Values(
							{"101", "101", "101", "101", "102", "102", "102", "101", "101", "101"}
						)
					),
					New Column( "Last Inspection Decision",
						Character,
						"Nominal",
						Set Values( {"", "", "", "VAI", "", "", "Code 1", "", "", "Code 2"} )
					),
					New Column( "Last Inspection Data",
						Character,
						"Nominal",
						Set Values(
							{"PRODUCT SPECIFICATIONS DEFECT", "CGMP Deviations", "21 CFR 211.113",
							"LIQ_US", "PRODUCT SPECIFICATIONS DEFECT", "21 CFR 211.113", "LIQ_US",
							"PRODUCT SPECIFICATIONS DEFECT", "CGMP Deviations", "21 CFR 211.113"}
						)
					)
				);

// Copy the table
dt2 = Eval(dt &amp;lt;&amp;lt; getScript);
dt2 &amp;lt;&amp;lt; setName(dt &amp;lt;&amp;lt; getName ||" Stacked");

// Get the values from the two columns of interest into lists
ids = Column(dt2, "ID") &amp;lt;&amp;lt; getValues;
vals = Column(dt2, "Last Inspection Data") &amp;lt;&amp;lt; getValues;

// Find out where we need to insert new values, get the required values, and insert them into the right positions
insertAfter = dt2 &amp;lt;&amp;lt; getRowsWhere(!IsMissing(:Last Inspection Decision));
for(r=1, r&amp;lt;= NItems(insertAfter), r++,
	InsertInto(ids, Column(dt2, "ID")[insertAfter[r]], insertAfter[r] + r);
	InsertInto(vals, Column(dt2, "Last Inspection Decision")[insertAfter[r]], insertAfter[r] + r);
);

// Add rows to teh copy of the table, insert the column values, and delete the column we don't need
dt2 &amp;lt;&amp;lt; addRows(NRows(insertAfter));
Column(dt2, "ID") &amp;lt;&amp;lt; setValues(ids);
Column(dt2, "Last Inspection Data") &amp;lt;&amp;lt; setValues(vals);
dt2 &amp;lt;&amp;lt; deleteColumns(:Last Inspection Decision);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 31 Mar 2017 16:09:11 GMT</pubDate>
    <dc:creator>ian_jmp</dc:creator>
    <dc:date>2017-03-31T16:09:11Z</dc:date>
    <item>
      <title>add rows based on a column values in the same data table</title>
      <link>https://community.jmp.com/t5/Discussions/add-rows-based-on-a-column-values-in-the-same-data-table/m-p/37652#M22087</link>
      <description>&lt;P&gt;Dear All,&lt;/P&gt;&lt;P&gt;I have data table that contain ID, last inspection data, and last inspection decision columns. I want to combine the last inspection data column with the last inspection decision in order to have one column (stacked) to be used in association analysis. For instance, one cluster of my data structure looks like the following:&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Last Inspection Decision &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Last Inspection Data&amp;nbsp;&lt;/P&gt;&lt;P&gt;101 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; PRODUCT SPECIFICATIONS DEFECT&lt;BR /&gt;101 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CGMP Deviations&lt;BR /&gt;101 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;21 CFR 211.113&lt;BR /&gt;101 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;VAI &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;LIQ_US&lt;/P&gt;&lt;P&gt;I would like to move Last Inspection Decision, in this case VAI, under Last Inspection Data column and create new row that has the same ID, in this case 101. Therefore I need my stacked data to be like:&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Last Inspection Data&amp;nbsp;&lt;/P&gt;&lt;P&gt;101 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;PRODUCT SPECIFICATIONS DEFECT&lt;BR /&gt;101 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CGMP Deviations&lt;BR /&gt;101 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;21 CFR 211.113&lt;BR /&gt;101 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; LIQ_US&lt;/P&gt;&lt;P&gt;101 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;VAI&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Moreover, some of these IDs are repeated but with different value in one or more of the Last Inspection Data. For instance, Lab DEFECT can be another problem for the same ID so I create another cluster of rows when ever any of these values differ from previous one.&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Last Inspection Decision &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Last Inspection Data&amp;nbsp;&lt;/P&gt;&lt;P&gt;101 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Lab&amp;nbsp;DEFECT&lt;BR /&gt;101 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CGMP Deviations&lt;BR /&gt;101 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;21 CFR 211.113&lt;BR /&gt;101 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;VAI &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;LIQ_US&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for your help in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Qais&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Mar 2017 12:12:02 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/add-rows-based-on-a-column-values-in-the-same-data-table/m-p/37652#M22087</guid>
      <dc:creator>qais_hatim_fda_</dc:creator>
      <dc:date>2017-03-30T12:12:02Z</dc:date>
    </item>
    <item>
      <title>Re: add rows based on a column values in the same data table</title>
      <link>https://community.jmp.com/t5/Discussions/add-rows-based-on-a-column-values-in-the-same-data-table/m-p/37686#M22091</link>
      <description>&lt;P&gt;This is not the most robust solution but give it a go:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = current data table ();

for each row( if(!is missing (:Last Inspection Decision),
dt &amp;lt;&amp;lt; add rows(1, row()),
is missing (:Last Inspection Data), :Last Inspection Data[row()] = :Last Inspection Decision[row()-1])
 );
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Mar 2017 16:30:27 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/add-rows-based-on-a-column-values-in-the-same-data-table/m-p/37686#M22091</guid>
      <dc:creator>ron_horne</dc:creator>
      <dc:date>2017-03-30T16:30:27Z</dc:date>
    </item>
    <item>
      <title>Re: add rows based on a column values in the same data table</title>
      <link>https://community.jmp.com/t5/Discussions/add-rows-based-on-a-column-values-in-the-same-data-table/m-p/37725#M22119</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;It is not working as I have more than 100,000 rows. I tried to break my data to three parts, each one with almost 35,000 rows, but it is not working. Any suggestion?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Qais&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Mar 2017 15:10:24 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/add-rows-based-on-a-column-values-in-the-same-data-table/m-p/37725#M22119</guid>
      <dc:creator>qais_hatim_fda_</dc:creator>
      <dc:date>2017-03-31T15:10:24Z</dc:date>
    </item>
    <item>
      <title>Re: add rows based on a column values in the same data table</title>
      <link>https://community.jmp.com/t5/Discussions/add-rows-based-on-a-column-values-in-the-same-data-table/m-p/37726#M22120</link>
      <description>&lt;P&gt;I'm not sure if I have understood correctly, but here's an alternative. If it's what you want, you also need to see how well it will scale.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;NamesDefaultToHere(1);

// Example table . . .
dt = New Table( "Inspection",
					Add Rows( 10 ),
					New Column( "ID",
						Character,
						"Nominal",
						Set Values(
							{"101", "101", "101", "101", "102", "102", "102", "101", "101", "101"}
						)
					),
					New Column( "Last Inspection Decision",
						Character,
						"Nominal",
						Set Values( {"", "", "", "VAI", "", "", "Code 1", "", "", "Code 2"} )
					),
					New Column( "Last Inspection Data",
						Character,
						"Nominal",
						Set Values(
							{"PRODUCT SPECIFICATIONS DEFECT", "CGMP Deviations", "21 CFR 211.113",
							"LIQ_US", "PRODUCT SPECIFICATIONS DEFECT", "21 CFR 211.113", "LIQ_US",
							"PRODUCT SPECIFICATIONS DEFECT", "CGMP Deviations", "21 CFR 211.113"}
						)
					)
				);

// Copy the table
dt2 = Eval(dt &amp;lt;&amp;lt; getScript);
dt2 &amp;lt;&amp;lt; setName(dt &amp;lt;&amp;lt; getName ||" Stacked");

// Get the values from the two columns of interest into lists
ids = Column(dt2, "ID") &amp;lt;&amp;lt; getValues;
vals = Column(dt2, "Last Inspection Data") &amp;lt;&amp;lt; getValues;

// Find out where we need to insert new values, get the required values, and insert them into the right positions
insertAfter = dt2 &amp;lt;&amp;lt; getRowsWhere(!IsMissing(:Last Inspection Decision));
for(r=1, r&amp;lt;= NItems(insertAfter), r++,
	InsertInto(ids, Column(dt2, "ID")[insertAfter[r]], insertAfter[r] + r);
	InsertInto(vals, Column(dt2, "Last Inspection Decision")[insertAfter[r]], insertAfter[r] + r);
);

// Add rows to teh copy of the table, insert the column values, and delete the column we don't need
dt2 &amp;lt;&amp;lt; addRows(NRows(insertAfter));
Column(dt2, "ID") &amp;lt;&amp;lt; setValues(ids);
Column(dt2, "Last Inspection Data") &amp;lt;&amp;lt; setValues(vals);
dt2 &amp;lt;&amp;lt; deleteColumns(:Last Inspection Decision);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 31 Mar 2017 16:09:11 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/add-rows-based-on-a-column-values-in-the-same-data-table/m-p/37726#M22120</guid>
      <dc:creator>ian_jmp</dc:creator>
      <dc:date>2017-03-31T16:09:11Z</dc:date>
    </item>
  </channel>
</rss>

