<?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 batch generate assigned memory variables from lists using JSL? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-batch-generate-assigned-memory-variables-from-lists-using/m-p/403824#M65438</link>
    <description>&lt;P&gt;One way:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

nam = {"A", "B", "C", "D", "E", "H"};
For(i = 1, i &amp;lt;= N Items(nam), i++,
	Eval(Parse("r" || nam[i] || "=" || Char(i) || ""))
);
Show(rA, rB, rC, rD, rE, rH);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But there are very little cases where I would do this. I would most likely always use Associative Arrays or lists to handle situations like this&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;nam = {"A", "B", "C", "D", "E", "H"};
vals = {1, 2, 3, 4, 5, 6};
Show(vals[Contains(nam, "D")]);&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;aa = Associative Array({"A", "B", "C", "D", "E", "H"},{1, 2, 3, 4, 5, 6});
Show(aa);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 26 Jul 2021 09:27:23 GMT</pubDate>
    <dc:creator>jthi</dc:creator>
    <dc:date>2021-07-26T09:27:23Z</dc:date>
    <item>
      <title>How to batch generate assigned memory variables from lists using JSL?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-batch-generate-assigned-memory-variables-from-lists-using/m-p/403804#M65436</link>
      <description>&lt;P&gt;For example, given a list of text, assign values by adding the letter "r" before each element and in the order in which the elements are in the list.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;nam = {"A","B","C","D","E","H"};&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This results in the following variables and their assignments:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;rA=1;
rB=2;
rC=3;
rD=4;
rE=5;
rH=6;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 19:53:18 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-batch-generate-assigned-memory-variables-from-lists-using/m-p/403804#M65436</guid>
      <dc:creator>lala</dc:creator>
      <dc:date>2023-06-09T19:53:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to batch generate assigned memory variables from lists using JSL?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-batch-generate-assigned-memory-variables-from-lists-using/m-p/403809#M65437</link>
      <description>&lt;P&gt;It's not work&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;nam = {"A", "B", "C", "D", "E", "H"};
For( i = 1, i &amp;lt;= N Items( nam ), i++,
	"r" || nam[i] = i
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Jul 2021 09:14:28 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-batch-generate-assigned-memory-variables-from-lists-using/m-p/403809#M65437</guid>
      <dc:creator>lala</dc:creator>
      <dc:date>2021-07-26T09:14:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to batch generate assigned memory variables from lists using JSL?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-batch-generate-assigned-memory-variables-from-lists-using/m-p/403824#M65438</link>
      <description>&lt;P&gt;One way:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

nam = {"A", "B", "C", "D", "E", "H"};
For(i = 1, i &amp;lt;= N Items(nam), i++,
	Eval(Parse("r" || nam[i] || "=" || Char(i) || ""))
);
Show(rA, rB, rC, rD, rE, rH);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But there are very little cases where I would do this. I would most likely always use Associative Arrays or lists to handle situations like this&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;nam = {"A", "B", "C", "D", "E", "H"};
vals = {1, 2, 3, 4, 5, 6};
Show(vals[Contains(nam, "D")]);&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;aa = Associative Array({"A", "B", "C", "D", "E", "H"},{1, 2, 3, 4, 5, 6});
Show(aa);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Jul 2021 09:27:23 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-batch-generate-assigned-memory-variables-from-lists-using/m-p/403824#M65438</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2021-07-26T09:27:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to batch generate assigned memory variables from lists using JSL?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-batch-generate-assigned-memory-variables-from-lists-using/m-p/404009#M65447</link>
      <description>&lt;P&gt;I did not know about &lt;EM&gt;As Scoped&lt;/EM&gt; until just now, and &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/5579"&gt;@Wendy_Murphrey&lt;/a&gt; it could use better documentation, but it lets you access a namespace a bit like an associative array.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;nam = {"A", "B", "C", "D", "E", "H"};
For( i = 1, i &amp;lt;= N Items( nam ), i++,
	As Scoped( Global, nam[i]) = i;
);

show(a,b,c,d,e,h);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="1 2 3 4 5 6 7"&gt;&lt;STRONG&gt;a = 1;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1 2 3 4 5 6 7"&gt;&lt;STRONG&gt;b = 2;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1 2 3 4 5 6 7"&gt;&lt;STRONG&gt;c = 3;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1 2 3 4 5 6 7"&gt;&lt;STRONG&gt;d = 4;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1 2 3 4 5 6 7"&gt;&lt;STRONG&gt;e = 5;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1 2 3 4 5 6 7"&gt;&lt;STRONG&gt;h = 6;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;Even though the documentation doesn't say it, it can be on the left hand side of = and the 2nd parameter can be a string.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;EM&gt;&lt;STRONG&gt;I agree, most times I'd prefer a real associative array over this technique because your code can break in a terrible way if the { list of variable names } happens to include a real variable in your code that you don't want overwritten:&lt;/STRONG&gt;&lt;/EM&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;EM&gt;&lt;STRONG&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="The list holding &amp;quot;nam&amp;quot; just clobbered the variable 'nam' which held the list..." style="width: 408px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/34551i3EBF6E7999146A22/image-size/large?v=v2&amp;amp;px=999" role="button" title="badAsScoped.PNG" alt="The list holding &amp;quot;nam&amp;quot; just clobbered the variable 'nam' which held the list..." /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;The list holding "nam" just clobbered the variable 'nam' which held the list...&lt;/span&gt;&lt;/span&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jul 2021 15:45:08 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-batch-generate-assigned-memory-variables-from-lists-using/m-p/404009#M65447</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2021-07-26T15:45:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to batch generate assigned memory variables from lists using JSL?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-batch-generate-assigned-memory-variables-from-lists-using/m-p/404010#M65448</link>
      <description>&lt;P&gt;A slight variation on building the AA using a matrix for the values:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;nam = {"A", "B", "C", "D", "E", "H"};
myvars = Associative Array( nam, 1 :: N Items( nam ) );

Show( myvars["A"], myvars["H"] );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="1 2 3 4 5 6 7"&gt;&lt;STRONG&gt;myvars["A"] = 1;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1 2 3 4 5 6 7"&gt;&lt;STRONG&gt;myvars["H"] = 6;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jul 2021 15:54:42 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-batch-generate-assigned-memory-variables-from-lists-using/m-p/404010#M65448</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2021-07-26T15:54:42Z</dc:date>
    </item>
  </channel>
</rss>

