<?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 Setting a variable name within a for loop in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Setting-a-variable-name-within-a-for-loop/m-p/54133#M30586</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I like to set variable names such as name1, name2,... in a for loop with the following arrangement:&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;name1 = ntable;
name2 ="A"||"_"||Flow[1];
name3 ="A"||"_"||Flow[2];&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and so on.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I made a below script and got&amp;nbsp; some error:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;name1 = ntable;
for (i=1, i&amp;lt;=Nitems, i++,
 Eval(
 Parse(
 "name"||char(i+1) = "A" ||"_"|| Flow[i];
 )
 )
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I appreciate your help. Thanks.&lt;/P&gt;</description>
    <pubDate>Thu, 29 Mar 2018 19:43:01 GMT</pubDate>
    <dc:creator>AT</dc:creator>
    <dc:date>2018-03-29T19:43:01Z</dc:date>
    <item>
      <title>Setting a variable name within a for loop</title>
      <link>https://community.jmp.com/t5/Discussions/Setting-a-variable-name-within-a-for-loop/m-p/54133#M30586</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I like to set variable names such as name1, name2,... in a for loop with the following arrangement:&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;name1 = ntable;
name2 ="A"||"_"||Flow[1];
name3 ="A"||"_"||Flow[2];&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and so on.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I made a below script and got&amp;nbsp; some error:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;name1 = ntable;
for (i=1, i&amp;lt;=Nitems, i++,
 Eval(
 Parse(
 "name"||char(i+1) = "A" ||"_"|| Flow[i];
 )
 )
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I appreciate your help. Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Mar 2018 19:43:01 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Setting-a-variable-name-within-a-for-loop/m-p/54133#M30586</guid>
      <dc:creator>AT</dc:creator>
      <dc:date>2018-03-29T19:43:01Z</dc:date>
    </item>
    <item>
      <title>Re: Setting a variable name within a for loop</title>
      <link>https://community.jmp.com/t5/Discussions/Setting-a-variable-name-within-a-for-loop/m-p/54138#M30588</link>
      <description>&lt;P&gt;You are not using the correct syntax for the renaming of a column.&amp;nbsp; Here is an example taken directly from&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; Help==&amp;gt;Scripting Index==&amp;gt;Column Scripting&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
:Age &amp;lt;&amp;lt; Set Name( "Time" );&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Mar 2018 19:02:16 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Setting-a-variable-name-within-a-for-loop/m-p/54138#M30588</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2018-03-29T19:02:16Z</dc:date>
    </item>
    <item>
      <title>Re: Setting a variable name within a for loop</title>
      <link>https://community.jmp.com/t5/Discussions/Setting-a-variable-name-within-a-for-loop/m-p/54150#M30596</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/2687"&gt;@txnelson&lt;/a&gt;&amp;nbsp;inteprets your question differently than I do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think you want to create a series of JSL variables with an index number as a part of the variable name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can do that but you'll need to build the entire expression as a string before you try to Parse() it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;flow = {"two", "three", "four"};

name1 = "A_one";
For( i = 1, i &amp;lt;= N Items( flow ), i++,
	Eval( Parse( "name" || Char( i + 1 ) || "= \!"A_" || flow[i] || "\!";" ) )
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;However, I'm not sure why you'd want to do this instead of using a list or associative array which has the indexing built in.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;names = {};
names[1] = "A_one";
For( i = 1, i &amp;lt;= N Items( flow ), i++,
	names[i + 1] = "A_" || flow[i]
);

Show( names[1], names[2], names[3], names[4] );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Mar 2018 19:58:04 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Setting-a-variable-name-within-a-for-loop/m-p/54150#M30596</guid>
      <dc:creator>Jeff_Perkinson</dc:creator>
      <dc:date>2018-03-29T19:58:04Z</dc:date>
    </item>
    <item>
      <title>Re: Setting a variable name within a for loop</title>
      <link>https://community.jmp.com/t5/Discussions/Setting-a-variable-name-within-a-for-loop/m-p/54162#M30601</link>
      <description>&lt;P&gt;Thanks Jeff. Both works fine but I like first one since my code is based on that definition. Instead of name1, I also like to define&lt;/P&gt;&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;name1jmp = &lt;SPAN class="s1"&gt;"$Documents/JMP/"&lt;/SPAN&gt; || &lt;SPAN class="s1"&gt;"A"&lt;/SPAN&gt; || &lt;SPAN class="s1"&gt;"_"&lt;/SPAN&gt; || Flow[i] || &lt;SPAN class="s1"&gt;".jmp"&lt;/SPAN&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you help me how to add that to previous script? Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Mar 2018 21:53:07 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Setting-a-variable-name-within-a-for-loop/m-p/54162#M30601</guid>
      <dc:creator>AT</dc:creator>
      <dc:date>2018-03-29T21:53:07Z</dc:date>
    </item>
    <item>
      <title>Re: Setting a variable name within a for loop</title>
      <link>https://community.jmp.com/t5/Discussions/Setting-a-variable-name-within-a-for-loop/m-p/54220#M30633</link>
      <description>&lt;P&gt;The technique is exactly the same. You're building up a string that you're going to parse into an expression and evaluate it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One thing that might be confusing you is the \!" below. Because you need your string to contain a " you need to escape it using \!.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;flow = {"two", "three", "four"};

name1 = "A_one";
For( i = 1, i &amp;lt;= N Items( flow ), i++,
	expr_string = "name" || Char( i + 1 ) || "jmp = \!"$Documents/JMP/" || "A_" || Flow[i] || ".jmp\!"";
	Show( expr_string );
	Eval( Parse( expr_string ) );
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Mar 2018 18:34:21 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Setting-a-variable-name-within-a-for-loop/m-p/54220#M30633</guid>
      <dc:creator>Jeff_Perkinson</dc:creator>
      <dc:date>2018-03-30T18:34:21Z</dc:date>
    </item>
    <item>
      <title>Re: Setting a variable name within a for loop</title>
      <link>https://community.jmp.com/t5/Discussions/Setting-a-variable-name-within-a-for-loop/m-p/54221#M30634</link>
      <description>&lt;P&gt;Thank you very much Jeff. I need a bit more help after I got the first part. Here is the script that works fine below:&lt;/P&gt;
&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If( Nitems == 5,
name1 = ntable;
name2 = "A" || "_" || Flow[1];
name3 = "A" || "_" || Flow[2];
name4 = "A" || "_" || Flow[3];
name5 = "A" || "_" || Flow[4];
name6 = "A" || "_" || Flow[5];
 
name1jmp = "$Documents/JMP/" || "A" || "_" || Flow[1] || ".jmp";
name2jmp = "$Documents/JMP/" || "A" || "_" || Flow[2] || ".jmp";
name3jmp = "$Documents/JMP/" || "A" || "_" || Flow[3] || ".jmp";
name4jmp = "$Documents/JMP/" || "A" || "_" || Flow[4] || ".jmp";
name5jmp = "$Documents/JMP/" || "A" || "_" || Flow[5] || ".jmp";
 
 
file1 = Open( ntablejmp );
file2 = Open( name1jmp );
file3 = Open( name2jmp );
file4 = Open( name3jmp );
file5 = Open( name4jmp );
file6 = Open( name5jmp );
 
 
listx = Eval List( {name1, name2, name3, name4, name5, name6} );
 
 
listexcelsheet = Eval List( {name1, name2, name3, name4, name5, name6} );
 
Create Excel Workbook( "$Documents/JMP/" || product_name || "_" || one_stage || ".xlsx", listx, listexcelsheet );
 
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p1"&gt;I am trying to create a for loop so that it works for any Nitems. I am using MAC machine and that's why it has be done this way. Thanks for all your continuous suppprt.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Mar 2018 18:59:48 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Setting-a-variable-name-within-a-for-loop/m-p/54221#M30634</guid>
      <dc:creator>AT</dc:creator>
      <dc:date>2018-03-30T18:59:48Z</dc:date>
    </item>
    <item>
      <title>Re: Setting a variable name within a for loop</title>
      <link>https://community.jmp.com/t5/Discussions/Setting-a-variable-name-within-a-for-loop/m-p/54227#M30636</link>
      <description>&lt;P&gt;What exactly are you struggling with? Are you receiving an error that you don't understand? I've shown the loops above that will work for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suggested earlier that you use a list instead of trying to create indexed JSL variable names. I don't see anything in the code you posted here that suggests that a list won't work for you. I'd strongly encourage&amp;nbsp;you to use lists instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;flow = {"one", "two", "three", "four", "five"};

names = {};
files = {};

For( i = 1, i &amp;lt;= N Items( flow ), i++,
	names[i] = "A_" || flow( i );
	files[i] = Open( "$Documents/JMP/A_" || Flow[i] || ".jmp" );
	Create Excel Workbook( "$Documents/JMP/" || product_name || "_" || one_stage || ".xlsx", files, listexcelsheet );

);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Mar 2018 19:13:55 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Setting-a-variable-name-within-a-for-loop/m-p/54227#M30636</guid>
      <dc:creator>Jeff_Perkinson</dc:creator>
      <dc:date>2018-03-30T19:13:55Z</dc:date>
    </item>
    <item>
      <title>Re: Setting a variable name within a for loop</title>
      <link>https://community.jmp.com/t5/Discussions/Setting-a-variable-name-within-a-for-loop/m-p/54233#M30641</link>
      <description>&lt;P&gt;Thanks Jeff. I tried your last script and changed the files and listexcelsheet to names and works perfectly. Thanks again for all your support.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Mar 2018 21:01:13 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Setting-a-variable-name-within-a-for-loop/m-p/54233#M30641</guid>
      <dc:creator>AT</dc:creator>
      <dc:date>2018-03-30T21:01:13Z</dc:date>
    </item>
  </channel>
</rss>

