<?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 Syntax error with &amp;quot;function&amp;quot; or &amp;quot;for&amp;quot; in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Syntax-error-with-quot-function-quot-or-quot-for-quot/m-p/685205#M87116</link>
    <description>&lt;P&gt;Hello JMPers,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My (JMP 14.3.0, W10) intention is to write a function that takes a table (dt) and list of unique Lot Numbers (uids) as input, and construct a table by concatenating a copy of dt for each uid, and filling in the appropriate Lot. No. information for each of those spots. The purpose of this is so I can later do join operations on the table. I am in the early part of the JSL learning curve, and I'm encountering the error as follows:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Unexpected "if". Perhaps there is a missing "," or ")". Trying to parse arguments of function "For".&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I presume I have a syntax issue with either my function or my For loop, but the syntax looks the same to me as other code I have that seems to be running correctly. Any/all advice is most welcome!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;pop_limits_with_uids = Function( {dt, uids},
	For( i = 1, i &amp;lt; N Items( uids ), i++,
		Print( "here" );
		If( i == 1,
			pop_dt = dt &amp;lt;&amp;lt; Subset( Output Table( "dt_copy" ), All rows, Selected columns only( 0 ) );
			dt_copy = pop_dt;
			Print( i );
		,
			dt_copy = dt &amp;lt;&amp;lt; Subset( Output Table( "dt_copy" ), All rows, Selected columns only( 0 ) )
		);	
		
		Column( dt_copy, "Lot No." )[{1, 2, 3}] = uids[i];	//dt_copy should have 3 rows. Set all 3 Lot No. to latest uid
		
		pop_dt &amp;lt;&amp;lt; concatenate( dt_copy, append to first table( 1 ) );	//add to the primary list
	);
	
	Close( dt_copy );
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Regards,&lt;/DIV&gt;&lt;DIV&gt;Scott&lt;/DIV&gt;</description>
    <pubDate>Mon, 09 Oct 2023 23:30:24 GMT</pubDate>
    <dc:creator>ScottMullin</dc:creator>
    <dc:date>2023-10-09T23:30:24Z</dc:date>
    <item>
      <title>Syntax error with "function" or "for"</title>
      <link>https://community.jmp.com/t5/Discussions/Syntax-error-with-quot-function-quot-or-quot-for-quot/m-p/685205#M87116</link>
      <description>&lt;P&gt;Hello JMPers,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My (JMP 14.3.0, W10) intention is to write a function that takes a table (dt) and list of unique Lot Numbers (uids) as input, and construct a table by concatenating a copy of dt for each uid, and filling in the appropriate Lot. No. information for each of those spots. The purpose of this is so I can later do join operations on the table. I am in the early part of the JSL learning curve, and I'm encountering the error as follows:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Unexpected "if". Perhaps there is a missing "," or ")". Trying to parse arguments of function "For".&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I presume I have a syntax issue with either my function or my For loop, but the syntax looks the same to me as other code I have that seems to be running correctly. Any/all advice is most welcome!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;pop_limits_with_uids = Function( {dt, uids},
	For( i = 1, i &amp;lt; N Items( uids ), i++,
		Print( "here" );
		If( i == 1,
			pop_dt = dt &amp;lt;&amp;lt; Subset( Output Table( "dt_copy" ), All rows, Selected columns only( 0 ) );
			dt_copy = pop_dt;
			Print( i );
		,
			dt_copy = dt &amp;lt;&amp;lt; Subset( Output Table( "dt_copy" ), All rows, Selected columns only( 0 ) )
		);	
		
		Column( dt_copy, "Lot No." )[{1, 2, 3}] = uids[i];	//dt_copy should have 3 rows. Set all 3 Lot No. to latest uid
		
		pop_dt &amp;lt;&amp;lt; concatenate( dt_copy, append to first table( 1 ) );	//add to the primary list
	);
	
	Close( dt_copy );
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Regards,&lt;/DIV&gt;&lt;DIV&gt;Scott&lt;/DIV&gt;</description>
      <pubDate>Mon, 09 Oct 2023 23:30:24 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Syntax-error-with-quot-function-quot-or-quot-for-quot/m-p/685205#M87116</guid>
      <dc:creator>ScottMullin</dc:creator>
      <dc:date>2023-10-09T23:30:24Z</dc:date>
    </item>
    <item>
      <title>Re: Syntax error with "function" or "for"</title>
      <link>https://community.jmp.com/t5/Discussions/Syntax-error-with-quot-function-quot-or-quot-for-quot/m-p/685252#M87121</link>
      <description>&lt;P&gt;I don't see a syntax issue in the JSL you posted in JMP 17.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once you get past that issue, whatever it turns out to be, you might want to use some local variables in the function. Something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;pop_limits_with_uids = Function( {dt, uids},
	{ i, pop_dt, dt_copy }, // these are local to the function
	For( i = 1, i &amp;lt; N Items( uids ), i++,
		Print( "here" );
		If( i == 1,
			pop_dt = dt &amp;lt;&amp;lt; Subset( Output Table( "dt_copy" ), All rows, Selected columns only( 0 ) );
			dt_copy = pop_dt;
			Print( i );
		,
			dt_copy = dt &amp;lt;&amp;lt; Subset( Output Table( "dt_copy" ), All rows, Selected columns only( 0 ) )
		);	
		
		Column( dt_copy, "Lot No." )[{1, 2, 3}] = uids[i];	//dt_copy should have 3 rows. Set all 3 Lot No. to latest uid
		
		pop_dt &amp;lt;&amp;lt; concatenate( dt_copy, append to first table( 1 ) );	//add to the primary list
	);
	
	Close( dt_copy );
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;there are other ways; this is what works best for me. It won't fix the problem you are currently facing.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2023 01:51:15 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Syntax-error-with-quot-function-quot-or-quot-for-quot/m-p/685252#M87121</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2023-10-10T01:51:15Z</dc:date>
    </item>
  </channel>
</rss>

