<?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: Select rows that match any value in a list in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Select-rows-that-match-any-value-in-a-list/m-p/53279#M30160</link>
    <description>&lt;P&gt;The issue is the same as it was in the first case.&amp;nbsp; codes[c] will not be interpreted in the formua. You have to substitute the actual value for codes[c] into the formula.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;For( c = 1, c &amp;lt;= N Items( codes ), c++,
	Eval(
		Substitute(
				Expr(
					CF &amp;lt;&amp;lt; New Column( "Code " || codes[c] || " Cost",
						Numeric,
						Continuous,
						Format( Currency ),
						Formula(
							If(
								And( :NC Code == __code__, :Disposition Type == "SCRAP-R" ),
									:NC Qty with Zeros * :Total Cost,
								And( :NC Code == __code__, :Disposition Type == "SCRAP-DNR" ),
									:NC Qty with Zeros * :Total Cost,
								And( :NC Code == __code__, :Disposition Type == "REWORK" ), 0,
								And( :NC Code == __code__, :Disposition Type == "DEVIATE-MATERIAL" ), 0,
								And( :NC Code == __code__, :Disposition Type == "DEVIATE-PROCESS" ), 0,
								And( :NC Code == __code__, :Disposition Type == "DEVIATE-PRODUCT" ), 0,
								0
							)
						)
					)
				),
			Expr( __code__ ), codes[c]
		)
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 16 Mar 2018 14:26:36 GMT</pubDate>
    <dc:creator>txnelson</dc:creator>
    <dc:date>2018-03-16T14:26:36Z</dc:date>
    <item>
      <title>Select rows that match any value in a list</title>
      <link>https://community.jmp.com/t5/Discussions/Select-rows-that-match-any-value-in-a-list/m-p/53057#M30017</link>
      <description>&lt;P&gt;I was having an issue with a more complicated script and wrote a simple test script to try and fix the issue, but can't figure out what's wrong. It's probably glaringly obvious, but I've been looking at it for too long to notice. I create a table with :Disposition Type, :NC Code, and :NC Qty. The original script takes user input to create the list of codes, but here I predefined the list. I want to create a column for each code listed in the codes list that copies over the value in :NC Qty if :NC Code matches the code from the list. It recognizes codes[c] to name the column, but not in the column formula. I've also tried using Contains instead of == in the formula, but that didn't seem to make a difference.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt; New Table( "NC Qty Col Test",
	Add Rows( 5 ),
	New Column( "Disposition Type",
		Character,
		"Nominal",
		Set Values(
			{"SCRAP-R", "SCRAP-DNR", "DEVIATE-MATERIAL", "DEVIATE-PROCESS",
			"DEVIATE-PRODUCT"}
		)
	),
	New Column( "NC Code",
		Character,
		"Nominal",
		Set Values( {"007", "014", "020", "007", "008"} )
	),
	New Column( "NC Qty",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [1, 2, 3, 4, 5] )
	)
);

codes = {"007", "014"};

For(c=1, c&amp;lt;=NItems(codes), c++,
	New Column("Code " || codes[c] || " NC Qty", Numeric, Continuous, Formula(If(:NC Code==codes[c], :NC Qty, 0 )));
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Mar 2018 14:19:02 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Select-rows-that-match-any-value-in-a-list/m-p/53057#M30017</guid>
      <dc:creator>rfeick</dc:creator>
      <dc:date>2018-03-13T14:19:02Z</dc:date>
    </item>
    <item>
      <title>Re: Select rows that match any value in a list</title>
      <link>https://community.jmp.com/t5/Discussions/Select-rows-that-match-any-value-in-a-list/m-p/53063#M30023</link>
      <description>&lt;P&gt;The issue is that your value of "c" changes, and is not static within the formula definition.&amp;nbsp; Therefore, you need to force the code to have a static value of "codes[c]" in the formula.&amp;nbsp; Below is one way to do that:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;New Table( "NC Qty Col Test",
	Add Rows( 5 ),
	New Column( "Disposition Type",
		Character,
		"Nominal",
		Set Values( {"SCRAP-R", "SCRAP-DNR", "DEVIATE-MATERIAL", "DEVIATE-PROCESS", "DEVIATE-PRODUCT"} )
	),
	New Column( "NC Code", Character, "Nominal", Set Values( {"007", "014", "020", "007", "008"} ) ),
	New Column( "NC Qty", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 2, 3, 4, 5] ) )
);

codes = {"007", "014"};

For( c = 1, c &amp;lt;= N Items( codes ), c++,
	Eval(
		Substitute(
				Expr(
					New Column( "Code " || codes[c] || " NC Qty", Numeric, Continuous, Formula( If( :NC Code == __code__, :NC Qty, 0 ) ) )
				),
			Expr( __code__ ), codes[c]
		)
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Mar 2018 14:51:42 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Select-rows-that-match-any-value-in-a-list/m-p/53063#M30023</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2018-03-13T14:51:42Z</dc:date>
    </item>
    <item>
      <title>Re: Select rows that match any value in a list</title>
      <link>https://community.jmp.com/t5/Discussions/Select-rows-that-match-any-value-in-a-list/m-p/53064#M30024</link>
      <description>&lt;P&gt;This one is a little tricky.&amp;nbsp; When you use variables in a formula you have to initialize them inside the formula.&amp;nbsp; But I did it without using formulas.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = New Table( "NC Qty Col Test",  Add Rows( 5 ),
	New Column( "Disposition Type", Character, "Nominal",
		Set Values(
			{"SCRAP-R", "SCRAP-DNR", "DEVIATE-MATERIAL", "DEVIATE-PROCESS",
			"DEVIATE-PRODUCT"}
		)
	),
	New Column( "NC Code", Character, "Nominal",
		Set Values( {"007", "014", "020", "007", "008"} )
	),
	New Column( "NC Qty", Numeric, "Continuous",
		Format( "Best", 12 ),
		Set Values( [1, 2, 3, 4, 5] )
	)
);
codes = {"007", "014"};
For(c = 1, c &amp;lt;= NItems(codes), c++,
	dt &amp;lt;&amp;lt; New Column("Code " || codes[c] || " NC Qty", numeric, "Continuous")
);
for (k = 1, k &amp;lt;= nitems(codes), k++,
	r = dt &amp;lt;&amp;lt; get rows where(:NC Code == codes[k]);
	colname = "Code " || codes[k] || " NC Qty";
	if (nrows(r) &amp;gt; 0,
		for (i = 1, i &amp;lt;= nrows(r), i++,
			one_row = r[i];
			column(dt, colname)[one_row] = column(dt, "NC Qty")[one_row];
		);
	);
);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Mar 2018 14:53:37 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Select-rows-that-match-any-value-in-a-list/m-p/53064#M30024</guid>
      <dc:creator>pmroz</dc:creator>
      <dc:date>2018-03-13T14:53:37Z</dc:date>
    </item>
    <item>
      <title>Re: Select rows that match any value in a list</title>
      <link>https://community.jmp.com/t5/Discussions/Select-rows-that-match-any-value-in-a-list/m-p/53084#M30039</link>
      <description>&lt;P&gt;Thanks so much for helping me figure it out! Either of those options would be great to fix my script!&lt;/P&gt;</description>
      <pubDate>Tue, 13 Mar 2018 19:16:44 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Select-rows-that-match-any-value-in-a-list/m-p/53084#M30039</guid>
      <dc:creator>rfeick</dc:creator>
      <dc:date>2018-03-13T19:16:44Z</dc:date>
    </item>
    <item>
      <title>Re: Select rows that match any value in a list</title>
      <link>https://community.jmp.com/t5/Discussions/Select-rows-that-match-any-value-in-a-list/m-p/53276#M30158</link>
      <description>&lt;P&gt;I was able to use the proposed solution to fix my original question and it seemed to make sense. However, then I realized that I had another portion of the same large script that does a very similar thing to create columns based on a variable value from a list. What I don't understand is why one works and the other doesn't. Here's the other section of script. In this portion I have a cost associated with the NC Code that is only supposed to be applied for Disposition Types of SCRAP-R and SCRAP-DNR. This cost is listed in the Total Cost column.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;For(c=1, c&amp;lt;=NItems(codes), c++,
				CF&amp;lt;&amp;lt;New Column("Code " || codes[c] || " Cost", Numeric, Continuous, Format(Currency), Formula(If(And(:NC Code == char(codes[c]), :Disposition Type == "SCRAP-R"), :NC Qty with Zeros * :Total Cost,
					And(:NC Code == char(codes[c]), :Disposition Type == "SCRAP-DNR"), :NC Qty with Zeros * :Total Cost,
					And(:NC Code == char(codes[c]), :Disposition Type == "REWORK"), 0,
					And(:NC Code == char(codes[c]), :Disposition Type == "DEVIATE-MATERIAL"), 0,
					And(:NC Code == char(codes[c]), :Disposition Type == "DEVIATE-PROCESS"), 0,
					And(:NC Code == char(codes[c]), :Disposition Type == "DEVIATE-PRODUCT"), 0,
					0
					);
				);); 
				); 
			);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Mar 2018 13:54:00 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Select-rows-that-match-any-value-in-a-list/m-p/53276#M30158</guid>
      <dc:creator>rfeick</dc:creator>
      <dc:date>2018-03-16T13:54:00Z</dc:date>
    </item>
    <item>
      <title>Re: Select rows that match any value in a list</title>
      <link>https://community.jmp.com/t5/Discussions/Select-rows-that-match-any-value-in-a-list/m-p/53279#M30160</link>
      <description>&lt;P&gt;The issue is the same as it was in the first case.&amp;nbsp; codes[c] will not be interpreted in the formua. You have to substitute the actual value for codes[c] into the formula.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;For( c = 1, c &amp;lt;= N Items( codes ), c++,
	Eval(
		Substitute(
				Expr(
					CF &amp;lt;&amp;lt; New Column( "Code " || codes[c] || " Cost",
						Numeric,
						Continuous,
						Format( Currency ),
						Formula(
							If(
								And( :NC Code == __code__, :Disposition Type == "SCRAP-R" ),
									:NC Qty with Zeros * :Total Cost,
								And( :NC Code == __code__, :Disposition Type == "SCRAP-DNR" ),
									:NC Qty with Zeros * :Total Cost,
								And( :NC Code == __code__, :Disposition Type == "REWORK" ), 0,
								And( :NC Code == __code__, :Disposition Type == "DEVIATE-MATERIAL" ), 0,
								And( :NC Code == __code__, :Disposition Type == "DEVIATE-PROCESS" ), 0,
								And( :NC Code == __code__, :Disposition Type == "DEVIATE-PRODUCT" ), 0,
								0
							)
						)
					)
				),
			Expr( __code__ ), codes[c]
		)
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Mar 2018 14:26:36 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Select-rows-that-match-any-value-in-a-list/m-p/53279#M30160</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2018-03-16T14:26:36Z</dc:date>
    </item>
  </channel>
</rss>

