<?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 SOLUTION - Re: Imbedding a For Loop in a Match Column Formula? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Imbedding-a-For-Loop-in-a-Match-Column-Formula/m-p/394509#M64487</link>
    <description>&lt;P&gt;My coworker helped me out and came up with this, it works perfectly! Still need to study why my previous attempts didn't work ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;New Column( "Sample",
		Character,
		Nominal,
		Formula(
			If(Contains(Init_IDs, :SampleID), New_IDs[Contains(Init_IDs, :SampleID)],
				Match(:SampleID,
                "C1", "Constant 1",
                "C2", "Constant 2",
				)
            )
        ),
    );&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 18 Jun 2021 14:58:12 GMT</pubDate>
    <dc:creator>amurphy</dc:creator>
    <dc:date>2021-06-18T14:58:12Z</dc:date>
    <item>
      <title>Imbedding a For Loop in a Match Column Formula?</title>
      <link>https://community.jmp.com/t5/Discussions/Imbedding-a-For-Loop-in-a-Match-Column-Formula/m-p/394466#M64482</link>
      <description>&lt;P&gt;&amp;nbsp;Hello, I am writing a script to automate my table manipulations (primarily adding new columns with match formulas) for data with a variable number of unique column contents and final outputs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wrote a script to identify the unique contents in :SampleID (saved in Init_IDs) and prompted the user to rename them in a pop-up window that saves in New_IDs, I can then create my new column with a standard match formula:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;New Column( "Sample",
		Character,
		Nominal,
		Formula(
			Match( :SampleID,
				"C1", "Constant 1",
				"C2", "Constant 2",
				Init_IDs[1], New_IDs[1],
				Init_IDs[2], New_IDs[2],
				Init_IDs[3], New_IDs[3],
				Init_IDs[4], New_IDs[4],
				Init_IDs[5], New_IDs[5],
				Init_IDs[6], New_IDs[6],
			)
		)
	);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This formula works for my test data set where the size of New_IDs was 6 but this will change so I'd like to use a For Loop to make it flexible, this is what I've tried but it doesn't work:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;New Column( "Sample",
		Character,
		Nominal,
		Formula(
			Match( :SampleID,
				"C1", "Constant 1",
				"C2", "Constant 2",
				) +
			For( i = 1, i &amp;lt;= N Items( New_IDs ), i++,
				Match( :SampleID,
					Init_IDs[i], New_IDs[i],
					)
				)
		),
	);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I've checked that N Items (New_IDs) generates the value 6. I tried the For Loop alone without the combination with the other Match formula and that also doesn't work so while the '+' in between may ultimately be a problem, the primary problem appears to be my for loop itself.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also attempted it simplified with an If statement instead of a Match formula, no luck there either:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;New Column( "Sample",
		Character,
		Nominal,
		Formula(
			For( i = 1, i &amp;lt;= 6, i++,
				If( :SampleID == Init_IDs[i],
					New_IDs[i]
				)
			)
		)
	);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:32:06 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Imbedding-a-For-Loop-in-a-Match-Column-Formula/m-p/394466#M64482</guid>
      <dc:creator>amurphy</dc:creator>
      <dc:date>2023-06-10T23:32:06Z</dc:date>
    </item>
    <item>
      <title>SOLUTION - Re: Imbedding a For Loop in a Match Column Formula?</title>
      <link>https://community.jmp.com/t5/Discussions/Imbedding-a-For-Loop-in-a-Match-Column-Formula/m-p/394509#M64487</link>
      <description>&lt;P&gt;My coworker helped me out and came up with this, it works perfectly! Still need to study why my previous attempts didn't work ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;New Column( "Sample",
		Character,
		Nominal,
		Formula(
			If(Contains(Init_IDs, :SampleID), New_IDs[Contains(Init_IDs, :SampleID)],
				Match(:SampleID,
                "C1", "Constant 1",
                "C2", "Constant 2",
				)
            )
        ),
    );&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Jun 2021 14:58:12 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Imbedding-a-For-Loop-in-a-Match-Column-Formula/m-p/394509#M64487</guid>
      <dc:creator>amurphy</dc:creator>
      <dc:date>2021-06-18T14:58:12Z</dc:date>
    </item>
  </channel>
</rss>

