<?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: Nested If statements in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Nested-If-statements/m-p/502955#M73587</link>
    <description>&lt;P&gt;Thank you for this, but I'm not sure I follow it fully. What do 12, 13, 14 etc. refer to in this case?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Wed, 08 Jun 2022 14:49:35 GMT</pubDate>
    <dc:creator>Agustin</dc:creator>
    <dc:date>2022-06-08T14:49:35Z</dc:date>
    <item>
      <title>Nested If statements</title>
      <link>https://community.jmp.com/t5/Discussions/Nested-If-statements/m-p/502600#M73581</link>
      <description>&lt;P&gt;Hi, I'm getting lost in implementing nested If statements in JSL:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt1:Run Validity &amp;lt;&amp;lt;
Set Formula(
	If( (:Sample Name == "NTC" &amp;amp; (:Target Name == "MIX 1 A" | :Target Name == "MIX 2 B" | :Target Name == "MIX 2 C" | :Target Name == "MIX 2 D" | :Target Name == "MIX 3 F" |
		 :Target Name == "MIX 3 G" | :Target Name == "MIX 3 H" | :Target Name == "MIX 4 I" | :Target Name == "MIX 4 J")), If( (:CT == "Undetermined"), "Pass", "Fail")),

	If( (:Sample Name == "PC" &amp;amp; :Target Name == "MIX 1 A"), If( (1 &amp;lt; :CT_numeric &amp;lt; 5), "Pass", "Fail")),
	If(	(:Sample Name == "PC" &amp;amp; :Target Name == "MIX 2 B"), If( (3 &amp;lt; :CT_numeric &amp;lt; 4), "Pass", "Fail")),
	If(	(:Sample Name == "PC" &amp;amp; :Target Name == "MIX 2 C"), If( (2 &amp;lt; :CT_numeric &amp;lt; 5), "Pass", "Fail")),
	If(	(:Sample Name == "PC" &amp;amp; :Target Name == "MIX 2 D"), If( (1 &amp;lt; :CT_numeric &amp;lt; 4), "Pass", "Fail")),
	If(	(:Sample Name == "PC" &amp;amp; :Target Name == "MIX 3 E"), If( (1 &amp;lt; :CT_numeric &amp;lt; 3), "Pass", "Fail")),
	If(	(:Sample Name == "PC" &amp;amp; :Target Name == "MIX 3 F"), If( (4 &amp;lt; :CT_numeric &amp;lt; 5), "Pass", "Fail")),
	If(	(:Sample Name == "PC" &amp;amp; :Target Name == "MIX 3 G"), If( (3 &amp;lt; :CT_numeric &amp;lt; 6), "Pass", "Fail")),
	If(	(:Sample Name == "PC" &amp;amp; :Target Name == "MIX 4 H"), If( (1 &amp;lt; :CT_numeric &amp;lt; 4), "Pass", "Fail")),
	If(	(:Sample Name == "PC" &amp;amp; :Target Name == "MIX 4 I"), If( (2 &amp;lt; :CT_numeric &amp;lt; 5), "Pass", "Fail")),
		
	If(	(:Sample Name != "PC" &amp;amp; (:Target Name == "MIX 1 IC" |:Target Name == "MIX 2 IC" | :Target Name == "MIX 3 IC" | :Target Name == "MIX 4 IC")), If((1 &amp;lt; :CT_numeric &amp;lt; 4), "Pass", "Fail"))

	);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Essentially I want for rows with sample name = NTC and Target Name one of Mix 1 A, Mix 1 B... if CT is undetermined return pass, if not fail&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a better way to do this with if statements? Or could you point out where I'm going wrong?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 17:00:45 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Nested-If-statements/m-p/502600#M73581</guid>
      <dc:creator>Agustin</dc:creator>
      <dc:date>2023-06-09T17:00:45Z</dc:date>
    </item>
    <item>
      <title>Re: Nested If statements</title>
      <link>https://community.jmp.com/t5/Discussions/Nested-If-statements/m-p/502637#M73582</link>
      <description>&lt;P&gt;I would suggest using Contains() instead of long copy pasted list of or statements and possible associative array for value comparison. If you need a formula you might have to use &lt;LI-MESSAGE title="Insert one expression into another using Eval Insert, Eval Expr, Parse, and Substitute" uid="48998" url="https://community.jmp.com/t5/JSL-Cookbook/Insert-one-expression-into-another-using-Eval-Insert-Eval-Expr/m-p/48998#U48998" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-tkb-thread lia-fa-icon lia-fa-tkb lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt; to get lists / associative arrays into the formula. This might give some ideas:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

aa_pc_limits = Associative Array();
aa_pc_limits["MIX 1 A"] = {1, 5};
aa_pc_limits["MIX 2 B"] = {3, 4};
aa_pc_limits["MIX 2 C"] = {2, 5};
aa_pc_limits["MIX 2 D"] = {1, 4};

ntc_valid = {"MTX 1 A", "MIX 2 B", "MIX 2C"};
non_pc_valid = {"MTX 1 IC", "MIX 2 IC", "MIX 3 IC"};


dt = New Table("Untitled",
	Add Rows(8),
	New Column("Sample Name",
		Character,
		"Nominal",
		Set Values({"NTC", "NTC", "AA", "AA", "AA", "PC", "PC", ""})
	),
	New Column("Target Name",
		Character,
		"Nominal",
		Set Values(
			{"MTX 1 A", "MTX AAAA", "MTX 1 IC", "MTX 1 IC", "AAA", "MIX 1 A", "BBB",
			""}
		)
	),
	New Column("CT_numeric",
		Numeric,
		"Continuous",
		Format("Best", 12),
		Set Values([., ., 2, 5, ., 2, 5, .])
	),
	New Column("CT",
		Character,
		"Nominal",
		Set Values({"Undetermined", "", "", "", "", "", "", ""})
	),
	New Column("Run Validity",
		Character,
		"Nominal",
		Set Values({"", "", "", "", "", "", "", ""})
	)
);

dt:Run Validity &amp;lt;&amp;lt; Set Formula(
	If(:Sample Name == "NTC",
		If(Contains(ntc_valid, :Target Name),
			If(:CT == "Undetermined",
				"Pass";
			, // else
				"Fail";
			)
		, // else
			"NOT DEFINED. NTC"
		)
	, :Sample Name != "PC",
		If(Contains(non_pc_valid, :Target Name),
			If((1 &amp;lt; :CT_numeric &amp;lt; 4),
				"Pass"
			,
				"Fail"
			)
		,
			"NOT DEFINED. NON-PC"
		)
	, :Sample Name == "PC",
		If(Contains(aa_pc_limits, :Target Name),
			IfMZ(aa_pc_limits[:Target Name][1] &amp;lt; :CT_numeric &amp;lt; aa_pc_limits[:Target Name][2],
				"PASS"
			,
				"FAIL"
			)
		,
			"NOT DEFINED. PC";
		)
	, //else
		"NOT DEFINED";
	);
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 Jun 2022 11:44:30 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Nested-If-statements/m-p/502637#M73582</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2022-06-08T11:44:30Z</dc:date>
    </item>
    <item>
      <title>Re: Nested If statements</title>
      <link>https://community.jmp.com/t5/Discussions/Nested-If-statements/m-p/502663#M73583</link>
      <description>&lt;P&gt;Another possible approach to managing a complicated set of rules&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = open("$sample_data/big class.jmp");
dt&amp;lt;&amp;lt;newcolumn("Run Validity", formula(
	lookup = asconstant([ // asConstant builds the lookup once
		"F" =&amp;gt; [ // rules for females, by age
			12 =&amp;gt; if(59&amp;lt;height&amp;lt;63,"Pass","Fail"),
			13 =&amp;gt; if(60&amp;lt;height&amp;lt;65,"Pass","Fail"),
			14 =&amp;gt; "Fail",
			15 =&amp;gt; "Pass",
			 =&amp;gt; "Maybe" // rule for other ages
		],
		"M" =&amp;gt; [ // rules for males, by age
			12 =&amp;gt; if(80&amp;lt;weight&amp;lt;90,"Pass","Fail"),
			13 =&amp;gt; if(name=="JOHN","Pass","Fail"),
			 =&amp;gt; "Possibly" // rule for other ages
		],
		 =&amp;gt; [ =&amp;gt; "?"]  // rule for unknown sex
	]);
	// use the table, above, to look up a rule, then evaluate the rule
	Eval( lookup[:sex][:age] )
));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Edit: changed =&amp;gt;"?" to =&amp;gt;[=&amp;gt;"?"] as described below.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jun 2022 16:07:26 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Nested-If-statements/m-p/502663#M73583</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2022-06-08T16:07:26Z</dc:date>
    </item>
    <item>
      <title>Re: Nested If statements</title>
      <link>https://community.jmp.com/t5/Discussions/Nested-If-statements/m-p/502955#M73587</link>
      <description>&lt;P&gt;Thank you for this, but I'm not sure I follow it fully. What do 12, 13, 14 etc. refer to in this case?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jun 2022 14:49:35 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Nested-If-statements/m-p/502955#M73587</guid>
      <dc:creator>Agustin</dc:creator>
      <dc:date>2022-06-08T14:49:35Z</dc:date>
    </item>
    <item>
      <title>Re: Nested If statements</title>
      <link>https://community.jmp.com/t5/Discussions/Nested-If-statements/m-p/502956#M73588</link>
      <description>&lt;P&gt;Thank you, I was looking for something like contains for ages but couldn't find it. And thank you for the nest if statements, I'll give this a go.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jun 2022 14:50:21 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Nested-If-statements/m-p/502956#M73588</guid>
      <dc:creator>Agustin</dc:creator>
      <dc:date>2022-06-08T14:50:21Z</dc:date>
    </item>
    <item>
      <title>Re: Nested If statements</title>
      <link>https://community.jmp.com/t5/Discussions/Nested-If-statements/m-p/502980#M73590</link>
      <description>&lt;P&gt;I would guess they refer to ages (and keys in associative arrays to perform lookup).&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jun 2022 15:06:55 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Nested-If-statements/m-p/502980#M73590</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2022-06-08T15:06:55Z</dc:date>
    </item>
    <item>
      <title>Re: Nested If statements</title>
      <link>https://community.jmp.com/t5/Discussions/Nested-If-statements/m-p/502989#M73591</link>
      <description>&lt;P&gt;12,13,14 are the ages of the big class rows.&lt;/P&gt;
&lt;P&gt;The [ square brackets ] for the outer associative array define two entries, one for "M" and one for "F". Each of those entries is also a an associative array with several entries indexed by ages. At the bottom you can see a 2-dimensional index using [sex][age] to look up a rule. Associative arrays also have an otherwise value that can be used when the key is not in the array.&lt;/P&gt;
&lt;P&gt;So, Lookup["M"] returns an AA with entries for 12 and 13; Lookup["M"][12] returns the 80...90 rule, and evaluating that uses the weight value from the current row to produce a string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The =&amp;gt;"?" needs to be =&amp;gt;[=&amp;gt;"?"] to actually work if there were values other than F and M. Otherwise Lookup["X"] would not return the expected AA for a 2nd index.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jun 2022 15:13:52 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Nested-If-statements/m-p/502989#M73591</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2022-06-08T15:13:52Z</dc:date>
    </item>
  </channel>
</rss>

