<?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: Value Label in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Value-Label/m-p/561957#M77502</link>
    <description>&lt;P&gt;Excellent!&amp;nbsp; Thank you so much.&lt;/P&gt;</description>
    <pubDate>Fri, 28 Oct 2022 17:46:27 GMT</pubDate>
    <dc:creator>Algerine</dc:creator>
    <dc:date>2022-10-28T17:46:27Z</dc:date>
    <item>
      <title>Value Label</title>
      <link>https://community.jmp.com/t5/Discussions/Value-Label/m-p/561474#M77456</link>
      <description>&lt;P&gt;I'm trying to change values in multiple columns using a For loop and an If statement.&amp;nbsp; unfortunately, while it creates the new columns properly, the values in the second column are for some reason copied into the first column as well.&amp;nbsp; What am I missing?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;New Table( "Untitled 11",
	Add Rows( 4 ),
	New Column( "Column_1",
		Character,
		"Nominal",
		Set Values( {"A1000", "A2000", "A3000", "A4000"} )
	),
	New Column( "Column_2",
		Character,
		"Nominal",
		Set Values( {"B5000", "B6000", "B7000", "B8000"} )
	)
);

OldColNames = { "Column_1", "Column_2" };

NewColNames = { "New_Column_1", "New_Column_2" };

nCols = N Items( OldColNames );

For( i = 1, i &amp;lt;= nCols, i++, 

	oldcol = OldColNames[i];
	newcol = NewColNames[i];

	New Column( newcol,
		Character,
		"Nominal",
		Formula(
			If(
				"A10" &amp;lt;= Left( As Column( oldcol ), 3 ) &amp;lt;= "A19", "A-One",
				"A20" &amp;lt;= Left( As Column( oldcol ), 3 ) &amp;lt;= "A29", "A-Two",
				"A30" &amp;lt;= Left( As Column( oldcol ), 3 ) &amp;lt;= "A39", "A-Three",
				"A40" &amp;lt;= Left( As Column( oldcol ), 3 ) &amp;lt;= "A49", "A-Four",
				"B50" &amp;lt;= Left( As Column( oldcol ), 3 ) &amp;lt;= "B59", "B-Five",
				"B60" &amp;lt;= Left( As Column( oldcol ), 3 ) &amp;lt;= "B69", "B-Six",
				"B70" &amp;lt;= Left( As Column( oldcol ), 3 ) &amp;lt;= "B79", "B-Seven",
				"B80" &amp;lt;= Left( As Column( oldcol ), 3 ) &amp;lt;= "B89", "B-Eight",
			)
		)
	);
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:56:01 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Value-Label/m-p/561474#M77456</guid>
      <dc:creator>Algerine</dc:creator>
      <dc:date>2023-06-10T23:56:01Z</dc:date>
    </item>
    <item>
      <title>Re: Value Label</title>
      <link>https://community.jmp.com/t5/Discussions/Value-Label/m-p/561479#M77458</link>
      <description>&lt;P&gt;It is because the name &lt;CODE class=" language-jsl"&gt;oldcol&lt;/CODE&gt; inside of the formulas is only evaluated (resolved) when the formula is run, and the formula does not run when the column is created but at a later point.&amp;nbsp; At that later point both columns refer to &lt;CODE class=" language-jsl"&gt;oldcol&lt;/CODE&gt;, which now resolves to the same column&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To fix this, you need to set the old col value at the time you're creating the column, like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;New Table( "Untitled 11",
	Add Rows( 4 ),
	New Column( "Column_1",
		Character,
		"Nominal",
		Set Values( {"A1000", "A2000", "A3000", "A4000"} )
	),
	New Column( "Column_2",
		Character,
		"Nominal",
		Set Values( {"B5000", "B6000", "B7000", "B8000"} )
	)
);

OldColNames = { "Column_1", "Column_2" };

NewColNames = { "New_Column_1", "New_Column_2" };

nCols = N Items( OldColNames );

For( i = 1, i &amp;lt;= nCols, i++, 

	oldcol = OldColNames[i];
	newcol = NewColNames[i];

	Eval( Eval Expr(
	New Column( newcol,
		Character,
		"Nominal",
		Formula(
			As Constant( col = As Name( Expr( old col ) ) );
			If(
				"A10" &amp;lt;= Left( col, 3 ) &amp;lt;= "A19", "A-One",
				"A20" &amp;lt;= Left( col, 3 ) &amp;lt;= "A29", "A-Two",
				"A30" &amp;lt;= Left( col, 3 ) &amp;lt;= "A39", "A-Three",
				"A40" &amp;lt;= Left( col, 3 ) &amp;lt;= "A49", "A-Four",
				"B50" &amp;lt;= Left( col, 3 ) &amp;lt;= "B59", "B-Five",
				"B60" &amp;lt;= Left( col, 3 ) &amp;lt;= "B69", "B-Six",
				"B70" &amp;lt;= Left( col, 3 ) &amp;lt;= "B79", "B-Seven",
				"B80" &amp;lt;= Left( col, 3 ) &amp;lt;= "B89", "B-Eight",
			)
		)
	);
	) );
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Here I'm using the &lt;CODE class=" language-jsl"&gt;Eval( Eval Expr( ... Expr( var ) ... ) )&lt;/CODE&gt; construct to pre-evaluate part of the script, and the &lt;CODE class=" language-jsl"&gt;As Constant()&lt;/CODE&gt; evaluates only for the first row and just keeps that value for all following rows (it can speed up formulas by preventing the name lookup time)&lt;/P&gt;</description>
      <pubDate>Fri, 28 Oct 2022 00:35:03 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Value-Label/m-p/561479#M77458</guid>
      <dc:creator>ErraticAttack</dc:creator>
      <dc:date>2022-10-28T00:35:03Z</dc:date>
    </item>
    <item>
      <title>Re: Value Label</title>
      <link>https://community.jmp.com/t5/Discussions/Value-Label/m-p/561957#M77502</link>
      <description>&lt;P&gt;Excellent!&amp;nbsp; Thank you so much.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Oct 2022 17:46:27 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Value-Label/m-p/561957#M77502</guid>
      <dc:creator>Algerine</dc:creator>
      <dc:date>2022-10-28T17:46:27Z</dc:date>
    </item>
  </channel>
</rss>

