<?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 pass a variable into a formula? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-pass-a-variable-into-a-formula/m-p/52351#M29636</link>
    <description>&lt;P&gt;You need something like this. When you change the Table Variable, the column updates.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Eval(
    Eval Expr(
        ARIMA Forecast(
            :age,
            40,
            ARIMA( 0, 1, 1, No Intercept( 1 ) ),
            {MA Coefficients( {Expr( :coef )} )},
            Row() - 9,
            Row() - 9
        )
    )
)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Using the same table variable idea, notice how the &lt;EM&gt;&lt;STRONG&gt;eval( eval expr( ... expr(:coef) ... ) )&lt;/STRONG&gt;&lt;/EM&gt; works. &lt;EM&gt;&lt;STRONG&gt;expr&lt;/STRONG&gt;&lt;/EM&gt;(:coef) identifies a snippet of the formula that needs a substitution made by evaluating it. &lt;EM&gt;&lt;STRONG&gt;evalexpr&lt;/STRONG&gt;&lt;/EM&gt;(...) does the evaluation of all the bits identified with expr, and returns an expression that still needs to be evaluated. &lt;EM&gt;&lt;STRONG&gt;eval&lt;/STRONG&gt;&lt;/EM&gt;(...) does that. (I changed all the parameters to make it do &lt;EM&gt;something&lt;/EM&gt; with bigclass...don't use mine! I'm not familiar with the ARIMA forecast functions, or if it should be used in a column formula like this. The scripting index example does not use a column formula.)&lt;/P&gt;</description>
    <pubDate>Wed, 28 Feb 2018 18:33:00 GMT</pubDate>
    <dc:creator>Craige_Hales</dc:creator>
    <dc:date>2018-02-28T18:33:00Z</dc:date>
    <item>
      <title>How to pass a variable into a formula?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-pass-a-variable-into-a-formula/m-p/52344#M29631</link>
      <description>&lt;P&gt;I am using the below syntax. I would like to modify one part of the formula which is the estimated MA coefficient.&lt;/P&gt;
&lt;P&gt;In this case, the value of the&amp;nbsp;&lt;SPAN&gt;MA Coefficient is 0.144654220611782.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;My numerous attempts so far, includign using lists, have fallen flat.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;How could I assign the coefficient value (of&amp;nbsp;0.144654220611782) to a "variable" and then use that "variable" in the formula? Meaning I assign the coefficient value before running the formula syntax, with the value passed into the formula in a suitable manner.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt &amp;lt;&amp;lt; New Column( "Yt Forecast1", Numeric, "Continuous", Format( "Best", 12 ),
Formula(
ARIMA Forecast(
:Yt,
50,
ARIMA( 0, 1, 1, No Intercept( 1 ) ),
{MA Coefficients( {0.144654220611782} )},
Row() - 50,
Row() - 50
)))&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Feb 2018 18:54:16 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-pass-a-variable-into-a-formula/m-p/52344#M29631</guid>
      <dc:creator>scottahindle</dc:creator>
      <dc:date>2018-02-28T18:54:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass a variable into a formula?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-pass-a-variable-into-a-formula/m-p/52347#M29633</link>
      <description>&lt;P&gt;edit: after re-reading, this might not be the answer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use a Table Variable, by scripting, or from the red triangle.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;New Table( "Untitled 46",
	Add Rows( 3 ),
	New Table Variable( "coef", 99.3 ),
	New Column( "Column 1",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Formula( :coef ),
		Set Selected
	)
)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Table Variable" style="width: 350px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/9643iCE2BD1A6CED6DEFE/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Table Variable" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Table Variable&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Feb 2018 17:52:19 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-pass-a-variable-into-a-formula/m-p/52347#M29633</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2018-02-28T17:52:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass a variable into a formula?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-pass-a-variable-into-a-formula/m-p/52351#M29636</link>
      <description>&lt;P&gt;You need something like this. When you change the Table Variable, the column updates.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Eval(
    Eval Expr(
        ARIMA Forecast(
            :age,
            40,
            ARIMA( 0, 1, 1, No Intercept( 1 ) ),
            {MA Coefficients( {Expr( :coef )} )},
            Row() - 9,
            Row() - 9
        )
    )
)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Using the same table variable idea, notice how the &lt;EM&gt;&lt;STRONG&gt;eval( eval expr( ... expr(:coef) ... ) )&lt;/STRONG&gt;&lt;/EM&gt; works. &lt;EM&gt;&lt;STRONG&gt;expr&lt;/STRONG&gt;&lt;/EM&gt;(:coef) identifies a snippet of the formula that needs a substitution made by evaluating it. &lt;EM&gt;&lt;STRONG&gt;evalexpr&lt;/STRONG&gt;&lt;/EM&gt;(...) does the evaluation of all the bits identified with expr, and returns an expression that still needs to be evaluated. &lt;EM&gt;&lt;STRONG&gt;eval&lt;/STRONG&gt;&lt;/EM&gt;(...) does that. (I changed all the parameters to make it do &lt;EM&gt;something&lt;/EM&gt; with bigclass...don't use mine! I'm not familiar with the ARIMA forecast functions, or if it should be used in a column formula like this. The scripting index example does not use a column formula.)&lt;/P&gt;</description>
      <pubDate>Wed, 28 Feb 2018 18:33:00 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-pass-a-variable-into-a-formula/m-p/52351#M29636</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2018-02-28T18:33:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass a variable into a formula?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-pass-a-variable-into-a-formula/m-p/52355#M29640</link>
      <description>&lt;P&gt;Here is a slightly different way of handling the same solution as Craige provided.&amp;nbsp; The only difference is that this version hard codes the Coef value into the formula, not requiring a Table Variable&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = Current Data Table();
coef = 99.3;
Eval(
	Substitute(
			Expr(
				New Table( "the table",
					Add Rows( 3 ),
					New Table Variable( "coef", 99.3 ),
					New Column( "Column 1",
						Numeric,
						"Continuous",
						Format( "Best", 12 ),
						Formula( __coef__ ),
						Set Selected
					)
				)
			),
		Expr( __coef__ ), coef
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Feb 2018 18:47:36 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-pass-a-variable-into-a-formula/m-p/52355#M29640</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2018-02-28T18:47:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass a variable into a formula?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-pass-a-variable-into-a-formula/m-p/52356#M29641</link>
      <description>&lt;P&gt;Another approach is to convert the formula to a string representation and then do standard string substitution, converting it back to an expression when you assign the column formula:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;strFml = Char(Expr(

	ARIMA Forecast(
		:Yt,
		50,
		ARIMA( 0, 1, 1, No Intercept( 1 ) ),
		{MA Coefficients( {_coeff_} )},
		Row() - 50,
		Row() - 50
	)
	
));;

coeffValue = 0.144;
SubstituteInto("_coeff_",coeffValue);

dt &amp;lt;&amp;lt; New Column("Y Forecast", numeric, Set Formula( Eval(Parse(strFml)) ));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Feb 2018 18:59:47 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-pass-a-variable-into-a-formula/m-p/52356#M29641</guid>
      <dc:creator>David_Burnham</dc:creator>
      <dc:date>2018-02-28T18:59:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass a variable into a formula?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-pass-a-variable-into-a-formula/m-p/52402#M29662</link>
      <description>&lt;P&gt;What has worked for me is this. I get the value "&lt;SPAN&gt;tempMACoeff&amp;nbsp;&lt;/SPAN&gt;" from the list from lstModel = ts &amp;lt;&amp;lt; Get Models; (ts is the time series analysis)&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The column formula accepts a new value for tempMACoeff&amp;nbsp;and will update...&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;col = dt &amp;lt;&amp;lt; New Column( "Yt-Forecast", Numeric);
dt &amp;lt;&amp;lt; set Table Variable( "coef", tempMACoeff );
col &amp;lt;&amp;lt; Set Formula( Eval(
Eval Expr(
ARIMA Forecast(
:Yt,
50,
ARIMA( 0, 1, 1, No Intercept( 1 ) ),
{MA Coefficients( {Expr( :coef )} )},//
Row() - 50,
Row() - 50
)
)
)); // set the formula&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Feb 2018 21:51:24 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-pass-a-variable-into-a-formula/m-p/52402#M29662</guid>
      <dc:creator>scottahindle</dc:creator>
      <dc:date>2018-02-28T21:51:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass a variable into a formula?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-pass-a-variable-into-a-formula/m-p/52403#M29663</link>
      <description>Dave, I wasn't able to get this to work out. I resorted to the below which seems to the job I'm hoping to get done.&lt;BR /&gt;Thanks, Scott.</description>
      <pubDate>Wed, 28 Feb 2018 21:48:03 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-pass-a-variable-into-a-formula/m-p/52403#M29663</guid>
      <dc:creator>scottahindle</dc:creator>
      <dc:date>2018-02-28T21:48:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass a variable into a formula?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-pass-a-variable-into-a-formula/m-p/52405#M29664</link>
      <description>&lt;P&gt;Column formulas subscribe to&amp;nbsp;other columns and table variables to listen for changes and reevaluate when that happens.&amp;nbsp; Not to other JSL variables though. So, the way it works for you, the formula can see the &lt;EM&gt;coef&lt;/EM&gt; variable and knows it should subscribe for changes. I think the other suggestions are replacing the variable with a constant, so the formula no longer knows it should subscribe to something.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Feb 2018 22:17:34 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-pass-a-variable-into-a-formula/m-p/52405#M29664</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2018-02-28T22:17:34Z</dc:date>
    </item>
  </channel>
</rss>

