<?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 Update New Table Variable value in Function in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-To-Update-New-Table-Variable-value-in-Function/m-p/683386#M86884</link>
    <description>&lt;P&gt;Oh, I missed that part. Got it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now it is working as expected.&amp;nbsp;Thanks Jim.&lt;/P&gt;</description>
    <pubDate>Tue, 03 Oct 2023 13:21:53 GMT</pubDate>
    <dc:creator>fahmadfu</dc:creator>
    <dc:date>2023-10-03T13:21:53Z</dc:date>
    <item>
      <title>How To Update New Table Variable value in Function</title>
      <link>https://community.jmp.com/t5/Discussions/How-To-Update-New-Table-Variable-value-in-Function/m-p/682883#M86849</link>
      <description>&lt;P&gt;What is the best way to update the New Table Variable value inside a function.&amp;nbsp;&lt;SPAN&gt;At this moment, I am doing it as below. However, I found that this Days variable will not get updated and&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;it will create a new variable called Days 2.&lt;/SPAN&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" );
dt &amp;lt;&amp;lt; New Table Variable( "Days", 42 );   // In original data table, Days set to default which is 42


// assume below is a new function, and I'm passing dt as input and I want to update the Days variable
myFunction = Function ({dt},
	
	// I want this Days variable get updated with new value below, 100
	dt &amp;lt;&amp;lt; New Table Variable ( "Days", 100);
	
	dt &amp;lt;&amp;lt; Select Where( :Name( "sex" ) == "F" );
	dt &amp;lt;&amp;lt; Subset( Copy formula( 1 ), Suppress formula evaluation( 0 ), Selected Rows( 1 ), Selected columns only( 0 ) );
	dt = Data Table (Current Data Table() &amp;lt;&amp;lt; Get Name());
);


myFunction(dt)&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Oct 2023 09:37:32 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-To-Update-New-Table-Variable-value-in-Function/m-p/682883#M86849</guid>
      <dc:creator>fahmadfu</dc:creator>
      <dc:date>2023-10-02T09:37:32Z</dc:date>
    </item>
    <item>
      <title>Re: How To Update New Table Variable value in Function</title>
      <link>https://community.jmp.com/t5/Discussions/How-To-Update-New-Table-Variable-value-in-Function/m-p/682897#M86850</link>
      <description>&lt;P&gt;Scripting Index&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_0-1696242700313.png" style="width: 999px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/57148iA94A611B5705E00A/image-size/large?v=v2&amp;amp;px=999" role="button" title="jthi_0-1696242700313.png" alt="jthi_0-1696242700313.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;so use &amp;lt;&amp;lt; Set Table Variable instead of creating a new one&lt;/P&gt;</description>
      <pubDate>Mon, 02 Oct 2023 10:32:10 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-To-Update-New-Table-Variable-value-in-Function/m-p/682897#M86850</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-10-02T10:32:10Z</dc:date>
    </item>
    <item>
      <title>Re: How To Update New Table Variable value in Function</title>
      <link>https://community.jmp.com/t5/Discussions/How-To-Update-New-Table-Variable-value-in-Function/m-p/682902#M86851</link>
      <description>&lt;P&gt;With a table variable, if you don't use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt &amp;lt;&amp;lt; Set Table Variable&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;you will need to delete the variable first, and then create it again.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt &amp;lt;&amp;lt; New Table Variable( "Days", 42 );   // In original data table, Days set to default which is 42


// assume below is a new function, and I'm passing dt as input and I want to update the Days variable
myFunction = Function ({dt},
	
	// I want this Days variable get updated with new value below, 100
	dt &amp;lt;&amp;lt; Delete Table Variable ( "Days");
	dt &amp;lt;&amp;lt; New Table Variable ( "Days", 100);
	
	dt &amp;lt;&amp;lt; Select Where( :Name( "sex" ) == "F" );
	dt &amp;lt;&amp;lt; Subset( Copy formula( 1 ), Suppress formula evaluation( 0 ), Selected Rows( 1 ), Selected columns only( 0 ) );
	dt = Data Table (Current Data Table() &amp;lt;&amp;lt; Get Name());
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2023 03:47:09 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-To-Update-New-Table-Variable-value-in-Function/m-p/682902#M86851</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2023-10-03T03:47:09Z</dc:date>
    </item>
    <item>
      <title>Re: How To Update New Table Variable value in Function</title>
      <link>https://community.jmp.com/t5/Discussions/How-To-Update-New-Table-Variable-value-in-Function/m-p/683259#M86872</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for this suggestion, and I think its working.&amp;nbsp; Additional to this, I've some extra question about this variable update. Do you know how can JSL update the data table variable based on new variable that we declared outside from the function? I modified the code as below and I think that it is not working. I want the Set Table Variable to be able to load values from a and b variable.&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" );
dt &amp;lt;&amp;lt; New Table Variable( "Days", 42 );   // In original data table, Days set to default which is 42

// declare new variable, this will be input from user
a = 100;
b = 200;

// assume below is a new function, and I'm passing dt and a as input
myFunction1 = Function ({dt, a},
	
	// I want this Days variable get updated with new value based on a
	dt &amp;lt;&amp;lt; Set Table Variable ( "Days", :a);
	
	dt &amp;lt;&amp;lt; Select Where( :Name( "sex" ) == "F" );
	dt &amp;lt;&amp;lt; Subset( Copy formula( 1 ), Suppress formula evaluation( 0 ), Selected Rows( 1 ), Selected columns only( 0 ) );
	dt = Data Table (Current Data Table() &amp;lt;&amp;lt; Get Name());
);

// assume below is a new function, and I'm passing dt and b as input
myFunction2 = Function ({dt, b},
	
	// I want this Days variable get updated with new value based on b
	dt &amp;lt;&amp;lt; Set Table Variable ( "Days", :b);
	
	dt &amp;lt;&amp;lt; Select Where( :Name( "sex" ) == "M" );
	dt &amp;lt;&amp;lt; Subset( Copy formula( 1 ), Suppress formula evaluation( 0 ), Selected Rows( 1 ), Selected columns only( 0 ) );
	dt = Data Table (Current Data Table() &amp;lt;&amp;lt; Get Name());
);

myFunction1(dt);
myFunction2(dt);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2023 02:44:43 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-To-Update-New-Table-Variable-value-in-Function/m-p/683259#M86872</guid>
      <dc:creator>fahmadfu</dc:creator>
      <dc:date>2023-10-03T02:44:43Z</dc:date>
    </item>
    <item>
      <title>Re: How To Update New Table Variable value in Function</title>
      <link>https://community.jmp.com/t5/Discussions/How-To-Update-New-Table-Variable-value-in-Function/m-p/683269#M86874</link>
      <description>&lt;OL&gt;
&lt;LI&gt;Your functions have 2 input variables specified, and you are only specifying one when you call the function.&lt;/LI&gt;
&lt;LI&gt;You are scoping the variables incorrectly.&amp;nbsp; Using&amp;nbsp; :a&amp;nbsp; in your script is indicating to JMP to look for a column named "a".&amp;nbsp; The colon ":" specified in front of a variable tells JMP the reference is pointing to a data table column.&amp;nbsp; Eight drop the colon from the variable reference or specify&amp;nbsp; &amp;nbsp; Here:a&amp;nbsp; &amp;nbsp; which is the formal name of the variable, when you have specified&lt;/LI&gt;
&lt;LI&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default to Here( 1 );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Tue, 03 Oct 2023 03:43:32 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-To-Update-New-Table-Variable-value-in-Function/m-p/683269#M86874</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2023-10-03T03:43:32Z</dc:date>
    </item>
    <item>
      <title>Re: How To Update New Table Variable value in Function</title>
      <link>https://community.jmp.com/t5/Discussions/How-To-Update-New-Table-Variable-value-in-Function/m-p/683386#M86884</link>
      <description>&lt;P&gt;Oh, I missed that part. Got it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now it is working as expected.&amp;nbsp;Thanks Jim.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2023 13:21:53 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-To-Update-New-Table-Variable-value-in-Function/m-p/683386#M86884</guid>
      <dc:creator>fahmadfu</dc:creator>
      <dc:date>2023-10-03T13:21:53Z</dc:date>
    </item>
  </channel>
</rss>

