<?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 to apply a formula to all columns in another table? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-apply-a-formula-to-all-columns-in-another-table/m-p/772600#M95306</link>
    <description>&lt;P&gt;You have placed the reference to the column in the Test table in the wrong place.&amp;nbsp; Also, I changed from using a format to using Set Each Value.&amp;nbsp; The end resulting calculation is the same, however the column is not a formula column.&amp;nbsp; This results in having the new data table being independent from the Test table.&amp;nbsp; I also changed the ending value for the For() loop.&amp;nbsp; Since you are including 2 rows both before and after, you can not calculate beyond nrows-2&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;names default to here(1);
Test = Open( "$SAMPLE_DATA/blood pressure.jmp" ); //open value data table
Testcols = Test &amp;lt;&amp;lt; Get Column Names( string, continuous ); //get column names
 
TestMA = New Table( "Test Table Smoothed" ); //make new table
TestMA &amp;lt;&amp;lt; add rows( N Rows( Test ) ); //make new table match rows with raw table
 
For( i = 1, i &amp;lt;= N Cols( Test )-2, i++,
	Eval(
		Parse(
			"TestMA &amp;lt;&amp;lt; New Column( \!"MA_" || Testcols[i] ||
			"\!",
numeric,
continuous,
set each value( Col Moving Average( test:" || Testcols[i] || ", 1, 2, 2 ) ) )"
		)
	);
);
TestMA &amp;lt;&amp;lt; delete columns( "column 1" );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Finally, please use the JSL Icon at the top of the preview screen to enter your code.&amp;nbsp; It makes for much easier reading.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code actually does not require the complexity of the Eval(Parse()) code.&amp;nbsp; It can just use open code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
Test = Open( "$SAMPLE_DATA/blood pressure.jmp" ); //open value data table
Testcols = Test &amp;lt;&amp;lt; Get Column Names( string, continuous ); //get column names
 
TestMA = New Table( "Test Table Smoothed" ); //make new table
TestMA &amp;lt;&amp;lt; add rows( N Rows( Test ) ); //make new table match rows with raw table
 
For( i = 1, i &amp;lt;= N Cols( Test ) - 2, i++,
	TestMA &amp;lt;&amp;lt; New Column( "MA_" || Testcols[i],
		numeric,
		continuous,
		set each value( Col Moving Average( test:Testcols[i], 1, 2, 2 ) )
	)
);
TestMA &amp;lt;&amp;lt; delete columns( "column 1" );&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 11 Jul 2024 20:36:43 GMT</pubDate>
    <dc:creator>txnelson</dc:creator>
    <dc:date>2024-07-11T20:36:43Z</dc:date>
    <item>
      <title>How to apply a formula to all columns in another table?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-apply-a-formula-to-all-columns-in-another-table/m-p/772590#M95305</link>
      <description>&lt;P&gt;I am trying to take a table and apply a moving average to every function to every column. The script below is what I am trying, based on what I saw in another thread here. The goal is to make a new table and then apply the function while referencing the original. However, I keep getting a scoped data table access error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Test = Open("C:\Users\abrokaw\Desktop\JMP MA Test Table.jmp"); //open value data table
Testcols = Test &amp;lt;&amp;lt; Get Column Names( string ); //get column names
 
TestMA = New Table( "Test Table Smoothed" ); //make new table
TestMA &amp;lt;&amp;lt; add rows(nrows(Test)); //make new table match rows with raw table
 
For( i = 1, i &amp;lt;= N Cols( Test ), i++,
Eval(
Parse(
"TestMA &amp;lt;&amp;lt; New Column( \!"MA_" || Testcols[i] || "\!",
numeric,
continuous,
formula( test:" ||
Testcols[i] || "Col Moving Average( :Value, 1, 2, 2 ) ) )'"
)
)
);
TestMA &amp;lt;&amp;lt; delete columns("column 1");
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;</description>
      <pubDate>Fri, 12 Jul 2024 04:02:17 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-apply-a-formula-to-all-columns-in-another-table/m-p/772590#M95305</guid>
      <dc:creator>GroupEdgeColt67</dc:creator>
      <dc:date>2024-07-12T04:02:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to apply a formula to all columns in another table?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-apply-a-formula-to-all-columns-in-another-table/m-p/772600#M95306</link>
      <description>&lt;P&gt;You have placed the reference to the column in the Test table in the wrong place.&amp;nbsp; Also, I changed from using a format to using Set Each Value.&amp;nbsp; The end resulting calculation is the same, however the column is not a formula column.&amp;nbsp; This results in having the new data table being independent from the Test table.&amp;nbsp; I also changed the ending value for the For() loop.&amp;nbsp; Since you are including 2 rows both before and after, you can not calculate beyond nrows-2&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;names default to here(1);
Test = Open( "$SAMPLE_DATA/blood pressure.jmp" ); //open value data table
Testcols = Test &amp;lt;&amp;lt; Get Column Names( string, continuous ); //get column names
 
TestMA = New Table( "Test Table Smoothed" ); //make new table
TestMA &amp;lt;&amp;lt; add rows( N Rows( Test ) ); //make new table match rows with raw table
 
For( i = 1, i &amp;lt;= N Cols( Test )-2, i++,
	Eval(
		Parse(
			"TestMA &amp;lt;&amp;lt; New Column( \!"MA_" || Testcols[i] ||
			"\!",
numeric,
continuous,
set each value( Col Moving Average( test:" || Testcols[i] || ", 1, 2, 2 ) ) )"
		)
	);
);
TestMA &amp;lt;&amp;lt; delete columns( "column 1" );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Finally, please use the JSL Icon at the top of the preview screen to enter your code.&amp;nbsp; It makes for much easier reading.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code actually does not require the complexity of the Eval(Parse()) code.&amp;nbsp; It can just use open code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
Test = Open( "$SAMPLE_DATA/blood pressure.jmp" ); //open value data table
Testcols = Test &amp;lt;&amp;lt; Get Column Names( string, continuous ); //get column names
 
TestMA = New Table( "Test Table Smoothed" ); //make new table
TestMA &amp;lt;&amp;lt; add rows( N Rows( Test ) ); //make new table match rows with raw table
 
For( i = 1, i &amp;lt;= N Cols( Test ) - 2, i++,
	TestMA &amp;lt;&amp;lt; New Column( "MA_" || Testcols[i],
		numeric,
		continuous,
		set each value( Col Moving Average( test:Testcols[i], 1, 2, 2 ) )
	)
);
TestMA &amp;lt;&amp;lt; delete columns( "column 1" );&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 Jul 2024 20:36:43 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-apply-a-formula-to-all-columns-in-another-table/m-p/772600#M95306</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2024-07-11T20:36:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to apply a formula to all columns in another table?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-apply-a-formula-to-all-columns-in-another-table/m-p/772646#M95316</link>
      <description>&lt;P&gt;You can also use Subset to copy the columns over (this will copy also table scripts and such, which can be a benefit or a problem). &lt;STRONG&gt;Remember to use Copy Formula(0) if you go with the Subset option and use formula columns for calculations&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp"); 
cont_cols = dt &amp;lt;&amp;lt; Get Column Names(string, continuous); 

ma_cols = {};
For(i = 1, i &amp;lt;= N Items(cont_cols), i++, // could use For Each but I try to avoid ... Each loops nowadays
	//Eval(EvalExpr()) isn't necessary here but makes debugghing much easier
	new_col = Eval(EvalExpr(
		dt &amp;lt;&amp;lt; New Column("MA_" || cont_cols[i], Numeric, Continuous, Formula( // I also try to avoid Set Each Value in cases like this so I use Formula here
			Col Moving Average(Expr(NameExpr(AsColumn(dt, cont_cols[i]))), 1, 2, 2)
		));
	));
	Insert Into(ma_cols, new_col &amp;lt;&amp;lt; get name);
);

dt_new = dt &amp;lt;&amp;lt; Subset(All Rows, Columns(ma_cols), Copy Formula(0), Output Table("Moving Averages"));
dt &amp;lt;&amp;lt; Delete Columns(ma_cols);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 Jul 2024 06:46:55 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-apply-a-formula-to-all-columns-in-another-table/m-p/772646#M95316</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-07-12T06:46:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to apply a formula to all columns in another table?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-apply-a-formula-to-all-columns-in-another-table/m-p/773069#M95389</link>
      <description>&lt;P&gt;Thanks, Jim. This change works for a test data set that I made. However, I'm still running into an issue with the same error message on my real data set. I think it has something to do with the column names because when I copy the column names over from my real data set to my test set, I get the same error there, as well. Are there certain characters in a column name that could cause this issue?&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jul 2024 16:02:04 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-apply-a-formula-to-all-columns-in-another-table/m-p/773069#M95389</guid>
      <dc:creator>GroupEdgeColt67</dc:creator>
      <dc:date>2024-07-15T16:02:04Z</dc:date>
    </item>
  </channel>
</rss>

