<?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 Create and populates new columns based categories in an existing column in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Create-and-populates-new-columns-based-categories-in-an-existing/m-p/267521#M52084</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to build a quick query in which a categorical column (test_article) is used to&amp;nbsp; create a series of column which contains only a subset of the information. If the script works as intended, the table would end up with 2 new columns (PBS vs ...).&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;test_article&lt;/TD&gt;&lt;TD&gt;measurement&lt;/TD&gt;&lt;TD&gt;PBS vs 709547&lt;/TD&gt;&lt;TD&gt;PBS vs 709139&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;PBS&lt;/TD&gt;&lt;TD&gt;1.23&lt;/TD&gt;&lt;TD&gt;PBS&lt;/TD&gt;&lt;TD&gt;PBS&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;PBS&lt;/TD&gt;&lt;TD&gt;1.456&lt;/TD&gt;&lt;TD&gt;PBS&lt;/TD&gt;&lt;TD&gt;PBS&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;709547&lt;/TD&gt;&lt;TD&gt;4.56&lt;/TD&gt;&lt;TD&gt;709547&lt;/TD&gt;&lt;TD&gt;EXCLUDE&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;709139&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;5.02&lt;/TD&gt;&lt;TD&gt;EXCLUDE&lt;/TD&gt;&lt;TD&gt;709139&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;709139&lt;/TD&gt;&lt;TD&gt;6.02&lt;/TD&gt;&lt;TD&gt;EXCLUDE&lt;/TD&gt;&lt;TD&gt;709139&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;709547&lt;/TD&gt;&lt;TD&gt;4.57&lt;/TD&gt;&lt;TD&gt;709547&lt;/TD&gt;&lt;TD&gt;EXCLUDE&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried the following script:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;NamesDefaultToHere(1);
dt=current data table();

row = Associative Array( :test_article ) &amp;lt;&amp;lt; Get Keys;
nc=N items (row);
For( i = 1, i &amp;lt;= nc, i++,
		new column("PBS vs "|| row[i],"Character", "Nominal", Formula(If( :test_article == "PBS", :test_article,
	If( :test_article == row[i],
		"test",
		"EXCLUDE"
	)
))));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Somehow, it does not populate any values in the new columns with the exception of 'PBS'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sebastien&lt;/P&gt;</description>
    <pubDate>Mon, 18 May 2020 20:01:08 GMT</pubDate>
    <dc:creator>Sburel</dc:creator>
    <dc:date>2020-05-18T20:01:08Z</dc:date>
    <item>
      <title>Create and populates new columns based categories in an existing column</title>
      <link>https://community.jmp.com/t5/Discussions/Create-and-populates-new-columns-based-categories-in-an-existing/m-p/267521#M52084</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to build a quick query in which a categorical column (test_article) is used to&amp;nbsp; create a series of column which contains only a subset of the information. If the script works as intended, the table would end up with 2 new columns (PBS vs ...).&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;test_article&lt;/TD&gt;&lt;TD&gt;measurement&lt;/TD&gt;&lt;TD&gt;PBS vs 709547&lt;/TD&gt;&lt;TD&gt;PBS vs 709139&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;PBS&lt;/TD&gt;&lt;TD&gt;1.23&lt;/TD&gt;&lt;TD&gt;PBS&lt;/TD&gt;&lt;TD&gt;PBS&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;PBS&lt;/TD&gt;&lt;TD&gt;1.456&lt;/TD&gt;&lt;TD&gt;PBS&lt;/TD&gt;&lt;TD&gt;PBS&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;709547&lt;/TD&gt;&lt;TD&gt;4.56&lt;/TD&gt;&lt;TD&gt;709547&lt;/TD&gt;&lt;TD&gt;EXCLUDE&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;709139&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;5.02&lt;/TD&gt;&lt;TD&gt;EXCLUDE&lt;/TD&gt;&lt;TD&gt;709139&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;709139&lt;/TD&gt;&lt;TD&gt;6.02&lt;/TD&gt;&lt;TD&gt;EXCLUDE&lt;/TD&gt;&lt;TD&gt;709139&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;709547&lt;/TD&gt;&lt;TD&gt;4.57&lt;/TD&gt;&lt;TD&gt;709547&lt;/TD&gt;&lt;TD&gt;EXCLUDE&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried the following script:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;NamesDefaultToHere(1);
dt=current data table();

row = Associative Array( :test_article ) &amp;lt;&amp;lt; Get Keys;
nc=N items (row);
For( i = 1, i &amp;lt;= nc, i++,
		new column("PBS vs "|| row[i],"Character", "Nominal", Formula(If( :test_article == "PBS", :test_article,
	If( :test_article == row[i],
		"test",
		"EXCLUDE"
	)
))));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Somehow, it does not populate any values in the new columns with the exception of 'PBS'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sebastien&lt;/P&gt;</description>
      <pubDate>Mon, 18 May 2020 20:01:08 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-and-populates-new-columns-based-categories-in-an-existing/m-p/267521#M52084</guid>
      <dc:creator>Sburel</dc:creator>
      <dc:date>2020-05-18T20:01:08Z</dc:date>
    </item>
    <item>
      <title>Re: Create and populates new columns based categories in an existing column</title>
      <link>https://community.jmp.com/t5/Discussions/Create-and-populates-new-columns-based-categories-in-an-existing/m-p/267561#M52091</link>
      <description>&lt;P&gt;The primary issue you are having is that within the definition of a formula, one can not have items that need to be evaluated.&amp;nbsp; JMP thinks everything within the formula definition is to be evaluated only when the formula is executed.&lt;/P&gt;
&lt;P&gt;Therefore, the formula that is passed into the New Column definition, must be complete in it's syntax.&amp;nbsp; The modification of your code below works with your sample data table.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = Current Data Table();

row = Associative Array( :test_article ) &amp;lt;&amp;lt; Get Keys;
nc = N Items( row );
For( i = 1, i &amp;lt;= nc, i++,
	Eval(
		Parse(
			"New Column( \!"PBS vs " || row[i] ||
			"\!",
		Character,
		Nominal,
		Formula(
		if (Row() == 1, theTest = \!""
			 || row[i] ||
			"\!"); 
			If( :test_article == \!"PBS\!",
				zip=:test_article,
				If( :test_article == theTest,
					zip=\!"test\!",
					zip=\!"EXCLUDE\!"
				)
			);
			zip
		)
	)
);"
		)
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="theformulas.PNG" style="width: 758px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/24064i4C5797C23A449DE3/image-size/large?v=v2&amp;amp;px=999" role="button" title="theformulas.PNG" alt="theformulas.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 18 May 2020 22:01:16 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-and-populates-new-columns-based-categories-in-an-existing/m-p/267561#M52091</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2020-05-18T22:01:16Z</dc:date>
    </item>
    <item>
      <title>Re: Create and populates new columns based categories in an existing column</title>
      <link>https://community.jmp.com/t5/Discussions/Create-and-populates-new-columns-based-categories-in-an-existing/m-p/267565#M52093</link>
      <description>&lt;P&gt;You need to get the value of row[i] into the formula. JMP doesn't evaluate expressions inside the Formula() part of the New Column() message.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use &lt;A href="https://www.jmp.com/support/help/en/15.1/#page/jmp/manipulating-expressions.shtml" target="_self"&gt;Substitute()&lt;/A&gt; to get the actual value of row[i] into the formula.&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 = Current Data Table();

row = Associative Array( :test_article ) &amp;lt;&amp;lt; Get Keys;
nc = N Items( row );
For( i = 1, i &amp;lt;= nc, i++,
	Eval(
		Substitute(
				Expr(
					New Column( "PBS vs " || row[i],
						"Character",
						"Nominal",
						Formula( If( :test_article == "PBS" | :test_article == ri, :test_article, "EXCLUDE" ) )
					)
				),
			Expr( ri ), Eval( row[i] )
		)
	)
);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 May 2020 22:08:31 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-and-populates-new-columns-based-categories-in-an-existing/m-p/267565#M52093</guid>
      <dc:creator>Jeff_Perkinson</dc:creator>
      <dc:date>2020-05-18T22:08:31Z</dc:date>
    </item>
    <item>
      <title>Re: Create and populates new columns based categories in an existing column</title>
      <link>https://community.jmp.com/t5/Discussions/Create-and-populates-new-columns-based-categories-in-an-existing/m-p/267568#M52094</link>
      <description>Works like a charm!&lt;BR /&gt;&lt;BR /&gt;Thanks</description>
      <pubDate>Mon, 18 May 2020 22:17:31 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-and-populates-new-columns-based-categories-in-an-existing/m-p/267568#M52094</guid>
      <dc:creator>Sburel</dc:creator>
      <dc:date>2020-05-18T22:17:31Z</dc:date>
    </item>
    <item>
      <title>Re: Create and populates new columns based categories in an existing column</title>
      <link>https://community.jmp.com/t5/Discussions/Create-and-populates-new-columns-based-categories-in-an-existing/m-p/267569#M52095</link>
      <description>Also works like a charm.&lt;BR /&gt;&lt;BR /&gt;Thanks a lot</description>
      <pubDate>Mon, 18 May 2020 22:17:51 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-and-populates-new-columns-based-categories-in-an-existing/m-p/267569#M52095</guid>
      <dc:creator>Sburel</dc:creator>
      <dc:date>2020-05-18T22:17:51Z</dc:date>
    </item>
  </channel>
</rss>

