<?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: Scripting For loop to multiply values across row in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Scripting-For-loop-to-multiply-values-across-row/m-p/368080#M61793</link>
    <description>&lt;P&gt;You sir, are absolutely wonderful! thank you so much it works perfect! I was definitely over complicating things haha. you are so helpful!&lt;/P&gt;</description>
    <pubDate>Mon, 15 Mar 2021 23:05:09 GMT</pubDate>
    <dc:creator>Cdougz</dc:creator>
    <dc:date>2021-03-15T23:05:09Z</dc:date>
    <item>
      <title>Scripting For loop to multiply values across row</title>
      <link>https://community.jmp.com/t5/Discussions/Scripting-For-loop-to-multiply-values-across-row/m-p/368037#M61787</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I am fairly new to scripting in JMP and have looked through many jmp forums for solutions but haven't been successful in modifying the solutions for my particular problem.&lt;/P&gt;
&lt;P&gt;I have a script that produces a table of unknown number of columns and want to multiply each value in the row (there is only one row in the table generated) across the columns produced (column 1 * column 2 * column 3* etc). I simplified the table for the example, the actual table could have many more columns.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My loop multiplies each row by the next one but doesn't give me the final answer of all the rows multiplied by each other. I also just want the end product of all the values multplied together and don't need the product of each incremental value. Any help is very much appreciated.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;New Table( "tsp",
	Add Rows( 1 ),
	New Column( "Row 1",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Selected,
		Set Values( [0.975] )
	),
	New Column( "Row 2",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Selected,
		Set Values( [0.985] )
	),
	New Column( "Row 3",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Selected,
		Set Values( [0.983] )
	),
	New Column( "Row 4",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Selected,
		Set Values( [0.839] )
	),
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Ncol = N col(tsp);
For( i = 1, i &amp;lt;= Ncol, i++, 
	For( j = i + 1, j &amp;lt;= Ncol, j++, 
		RTP = Eval( Column( i ) &amp;lt;&amp;lt; Get Name ) || " * " || Eval( Column( i+=1 ) &amp;lt;&amp;lt; Get Name );
		New Column( RTP, Numeric , seteachvalue( Column( i )[] * Column( i+=1 )[]) );
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 22:08:29 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Scripting-For-loop-to-multiply-values-across-row/m-p/368037#M61787</guid>
      <dc:creator>Cdougz</dc:creator>
      <dc:date>2023-06-09T22:08:29Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting For loop to multiply values across row</title>
      <link>https://community.jmp.com/t5/Discussions/Scripting-For-loop-to-multiply-values-across-row/m-p/368049#M61789</link>
      <description>&lt;P&gt;You are working too hard.&amp;nbsp; Below is what I believe you want&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;names default to here( 1 );
dt = New Table( "tsp",
	Add Rows( 1 ),
	New Column( "Row 1",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Selected,
		Set Values( [0.975] )
	),
	New Column( "Row 2",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Selected,
		Set Values( [0.985] )
	),
	New Column( "Row 3",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Selected,
		Set Values( [0.983] )
	),
	New Column( "Row 4",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Selected,
		Set Values( [0.839] )
	),

);

Ncol = N Col( dt ); // or NCol = N Col( data table("tsp"));
value = 1;
For( i = 1, i &amp;lt;= Ncol, i++,
	value = Column( dt, i )[1] * value
);
Show( value );&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 Mar 2021 21:49:11 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Scripting-For-loop-to-multiply-values-across-row/m-p/368049#M61789</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-03-15T21:49:11Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting For loop to multiply values across row</title>
      <link>https://community.jmp.com/t5/Discussions/Scripting-For-loop-to-multiply-values-across-row/m-p/368080#M61793</link>
      <description>&lt;P&gt;You sir, are absolutely wonderful! thank you so much it works perfect! I was definitely over complicating things haha. you are so helpful!&lt;/P&gt;</description>
      <pubDate>Mon, 15 Mar 2021 23:05:09 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Scripting-For-loop-to-multiply-values-across-row/m-p/368080#M61793</guid>
      <dc:creator>Cdougz</dc:creator>
      <dc:date>2021-03-15T23:05:09Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting For loop to multiply values across row</title>
      <link>https://community.jmp.com/t5/Discussions/Scripting-For-loop-to-multiply-values-across-row/m-p/368228#M61815</link>
      <description>&lt;P&gt;All you need after New Table() is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Product( i = 1, N Col( dt ), Column( dt, i )[1] );&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Mar 2021 16:24:50 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Scripting-For-loop-to-multiply-values-across-row/m-p/368228#M61815</guid>
      <dc:creator>Mark_Bailey</dc:creator>
      <dc:date>2021-03-17T16:24:50Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting For loop to multiply values across row</title>
      <link>https://community.jmp.com/t5/Discussions/Scripting-For-loop-to-multiply-values-across-row/m-p/368778#M61863</link>
      <description>&lt;P&gt;I tried to put this into a For Each Row for situations where I would have mulitple rows to iterate through with this formula but it doesn't seem to be working and i'm not sure what my error is..I get the correct value in "RTP" for the first row "A" (86.9%) and then all the rest of the rows show the same value (75.5%) when they should all be different ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;New Table( "tsp",
	Add Rows( 5 ),
	New Column( "Site",
		Character,
		"Nominal",
		Set Selected,
		Set Values( {"A", "B", "C", "D", "E"} )
	),
	New Column( "Row 1",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Selected,
		Set Values(
			[0.974, 0.872, 0.927,
			0.974, 0.9033]
		)
	),
	New Column( "Row 2",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Selected,
		Set Values(
			[0.968, 0.902, 0.931, .,
			0.962]
		)
	),
	New Column( "Row 3",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Selected,
		Set Values(
			[0.944, 0.968, 0.987, ., .]
		)
	),
	New Column( "Row 4",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Selected,
		Set Values( [0.9847, 0.9471, ., ., .] )
	),
	New Column( "Row 5",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Selected,
		Set Values( [0.990, 0.994, ., ., .] )
	)	
);&lt;/PRE&gt;&lt;PRE&gt;tsp &amp;lt;&amp;lt; New Column("RTP", numeric, continuous, Format(Percent, 1));&lt;BR /&gt;
for each row(:RTP= Product( i = 2, N Col( tsp), Column( tsp, i )[1] )); &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Mar 2021 19:38:34 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Scripting-For-loop-to-multiply-values-across-row/m-p/368778#M61863</guid>
      <dc:creator>Cdougz</dc:creator>
      <dc:date>2021-03-17T19:38:34Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting For loop to multiply values across row</title>
      <link>https://community.jmp.com/t5/Discussions/Scripting-For-loop-to-multiply-values-across-row/m-p/368791#M61866</link>
      <description>&lt;P&gt;nvm i found the error with the brackets at the end containing a 1 when it should have been empty, my code should have been&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;tsp &amp;lt;&amp;lt; New Column("RTP", numeric, continuous, Format(Percent, 1));

for each row(:RTP= Product( i = 2, N Col( tsp), Column( tsp, i )[] ))&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Mar 2021 20:48:07 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Scripting-For-loop-to-multiply-values-across-row/m-p/368791#M61866</guid>
      <dc:creator>Cdougz</dc:creator>
      <dc:date>2021-03-17T20:48:07Z</dc:date>
    </item>
  </channel>
</rss>

