<?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: For Loop to Create Columns with Moving average formulas in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/For-Loop-to-Create-Columns-with-Moving-average-formulas/m-p/822766#M100258</link>
    <description>&lt;P&gt;Perfect!&amp;nbsp; Thank you!&lt;/P&gt;</description>
    <pubDate>Sat, 14 Dec 2024 12:27:26 GMT</pubDate>
    <dc:creator>jmm1974</dc:creator>
    <dc:date>2024-12-14T12:27:26Z</dc:date>
    <item>
      <title>For Loop to Create Columns with Moving average formulas</title>
      <link>https://community.jmp.com/t5/Discussions/For-Loop-to-Create-Columns-with-Moving-average-formulas/m-p/822729#M100249</link>
      <description>&lt;P&gt;I'm very new to jmp, trying to move from spreadsheets for big datasets.&amp;nbsp; I'm trying to create a series of columns to calculate different moving averages for a data column (xV-C).&amp;nbsp; I have most of the code working to create the columns, but the formula for each created column uses the for-loop variable (j) instead of the value for the for-loop (10, 11, 12...) for each column.&amp;nbsp; I think I need to do something with Eval and Parse, but I can't figure it out.&amp;nbsp; This is what I have so far:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;For(j = 10, j &amp;lt;= 12, j++,
	New Column("xF-C MA " || Char(j), Numeric, Formula(Col Moving Average(:"xV-C"n, 1, j - 1)))
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;I'm sure this is an easy one for someone!&amp;nbsp; I appreciate the help!&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Dec 2024 07:11:30 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/For-Loop-to-Create-Columns-with-Moving-average-formulas/m-p/822729#M100249</guid>
      <dc:creator>jmm1974</dc:creator>
      <dc:date>2024-12-14T07:11:30Z</dc:date>
    </item>
    <item>
      <title>Re: For Loop to Create Columns with Moving average formulas</title>
      <link>https://community.jmp.com/t5/Discussions/For-Loop-to-Create-Columns-with-Moving-average-formulas/m-p/822739#M100250</link>
      <description>&lt;P&gt;Welcome to the community&lt;/P&gt;
&lt;P&gt;With a variable specified in the formula, "J" and the changing of its value in the JSL, the columns with the variable will change as the value of "J" changes.&amp;nbsp; To rectify this, one needs to evaluate the value of the variable "J" as the formula is specified to JMP.&lt;/P&gt;
&lt;P&gt;Eval(EvalExpr()) will force the evaluation before JMP parses the code&lt;/P&gt;
&lt;P&gt;Try this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;For( j = 10, j &amp;lt;= 12, j++,
	Eval(
		Eval Expr(
			New Column( "xF-C MA x " || Char( j ),
				Numeric,
				Formula( Col Moving Average( :"xV-C"n, 1, Expr( j - 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>Sat, 14 Dec 2024 03:26:25 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/For-Loop-to-Create-Columns-with-Moving-average-formulas/m-p/822739#M100250</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2024-12-14T03:26:25Z</dc:date>
    </item>
    <item>
      <title>Re: For Loop to Create Columns with Moving average formulas</title>
      <link>https://community.jmp.com/t5/Discussions/For-Loop-to-Create-Columns-with-Moving-average-formulas/m-p/822761#M100254</link>
      <description>&lt;P&gt;I like using Eval+EvalExpr but there is one more good option Eval+Substitute which can sometimes be easier to read (not always!).&amp;nbsp;In your case it could look something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");

For(j = 10, j &amp;lt;= 12, j++,
	Eval(Substitute(
		Expr(
			dt &amp;lt;&amp;lt; New Column("height " || Char(j), Numeric, Formula(Col Moving Average(:height, 1, _lag_)))
		),
		Expr(_lag_), j - 1
	));
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good (old) post related to this topic&amp;nbsp; &lt;LI-MESSAGE title="Insert one expression into another using Eval Insert, Eval Expr, Parse, and Substitute" uid="48998" url="https://community.jmp.com/t5/JSL-Cookbook-Archived/Insert-one-expression-into-another-using-Eval-Insert-Eval-Expr/m-p/48998#U48998" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-tkb-thread lia-fa-icon lia-fa-tkb lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Dec 2024 07:15:43 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/For-Loop-to-Create-Columns-with-Moving-average-formulas/m-p/822761#M100254</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-12-14T07:15:43Z</dc:date>
    </item>
    <item>
      <title>Re: For Loop to Create Columns with Moving average formulas</title>
      <link>https://community.jmp.com/t5/Discussions/For-Loop-to-Create-Columns-with-Moving-average-formulas/m-p/822766#M100258</link>
      <description>&lt;P&gt;Perfect!&amp;nbsp; Thank you!&lt;/P&gt;</description>
      <pubDate>Sat, 14 Dec 2024 12:27:26 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/For-Loop-to-Create-Columns-with-Moving-average-formulas/m-p/822766#M100258</guid>
      <dc:creator>jmm1974</dc:creator>
      <dc:date>2024-12-14T12:27:26Z</dc:date>
    </item>
  </channel>
</rss>

