<?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: Help with If Statement in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Help-with-If-Statement/m-p/389391#M63962</link>
    <description>&lt;P&gt;Good point about the column name changing. It makes it harder to write the JSL for subsequent processing. Probably you want the same column name for all the cases, something like "status" or "action type".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 29 May 2021 15:46:36 GMT</pubDate>
    <dc:creator>Craige_Hales</dc:creator>
    <dc:date>2021-05-29T15:46:36Z</dc:date>
    <item>
      <title>Help with If Statement</title>
      <link>https://community.jmp.com/t5/Discussions/Help-with-If-Statement/m-p/389341#M63947</link>
      <description>&lt;P&gt;I'm currently trying to write a script that reads a column from my data table, and runs a different set of functions depending on the value of that column. For example,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the data in Column A = A, create a new column called "A" and run the functions (A to C) below.&lt;/P&gt;
&lt;P&gt;If the data in Column A = B, create a new column called "B" and run the functions (D to F) below instead.&lt;/P&gt;
&lt;P&gt;Else, create a new column called "N/A".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I run my script, it will always create the new column "N/A" even if the value is "A" or "B". It will also not run any of the functions I have written for the "A" and "B" conditions. I feel like I'm missing something very obvious.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Current Data Table();
If(
:Column A&amp;nbsp;== "A", dt &amp;lt;&amp;lt; New Column( "A", character, nominal ),
Function A
Function B
Function C

:Column B&amp;nbsp;== "B", dt &amp;lt;&amp;lt; New Column( "B", character, nominal ),
Function D
Function E
Function F

dt &amp;lt;&amp;lt; New Column( "N/A", character, nominal )
)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 19:48:09 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Help-with-If-Statement/m-p/389341#M63947</guid>
      <dc:creator>cheeseistasty</dc:creator>
      <dc:date>2023-06-09T19:48:09Z</dc:date>
    </item>
    <item>
      <title>Re: Help with If Statement</title>
      <link>https://community.jmp.com/t5/Discussions/Help-with-If-Statement/m-p/389354#M63948</link>
      <description>&lt;P&gt;&lt;LI-MESSAGE title="If Secrets" uid="39558" url="https://community.jmp.com/t5/Uncharted/If-Secrets/m-p/39558#U39558" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-blog-thread lia-fa-icon lia-fa-blog lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;might help. Commas separate the &lt;EM&gt;clauses&lt;/EM&gt; in an if statement. Semicolons separate statements &lt;EM&gt;within&lt;/EM&gt; a clause.&lt;/P&gt;&lt;P&gt;You probably want something like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Current Data Table();
If( :Column A == "A", // condition, followed by a comma
     dt &amp;lt;&amp;lt; New Column( "A", character, nominal ); // one or more stmts
     Function A(); // with ; separators
     Function B();
     Function C(); // last statement has optional ; and required comma next line
, /* else if */ :Column B == "B", // 2nd condition followed by comma
     dt &amp;lt;&amp;lt; New Column( "B", character, nominal );
     Function D();
     Function E();
     Function F() // again, another comma. ; omitted for example...I prefer to use them
, /* else */ 
     dt &amp;lt;&amp;lt; New Column( "N/A", character, nominal ) // no more commas, this is the otherwise
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I like to indent and comment the /* else if */ and /* else */ to make it easier to follow.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 29 May 2021 15:49:52 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Help-with-If-Statement/m-p/389354#M63948</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2021-05-29T15:49:52Z</dc:date>
    </item>
    <item>
      <title>Re: Help with If Statement</title>
      <link>https://community.jmp.com/t5/Discussions/Help-with-If-Statement/m-p/389360#M63949</link>
      <description>&lt;P&gt;Given the scenarios you specified, the script below, generates the 3 cases&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;A exists in Column A&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;B exists in Column B&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Neither A or B exist&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ab.PNG" style="width: 725px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/33151i66C32F9CCE6BBEBF/image-size/large?v=v2&amp;amp;px=999" role="button" title="ab.PNG" alt="ab.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

A = Function( {},
	Show( "Function A" )
);
B = Function( {},
	Show( "Function B" )
);
C = Function( {},
	Show( "Function C" )
);
D = Function( {},
	Show( "Function D" )
);
EE = Function( {},
	Show( "Function EE" )
);
F = Function( {},
	Show( "Function F" )
);

// First Example Column A has the value A
dt1 = New Table( "Example1",
	Add Rows( 1 ),
	New Column( "Column A", Character, "Nominal", Set Values( {"A"} ) ),
	New Column( "Column B", Character, "Nominal", Set Values( {""} ) )
);
Wait( 5 );

If(
	:Column A[1] == "A",
		dt1 &amp;lt;&amp;lt; New Column( "A", character, nominal );
		A();
		B();
		C();,
	:Column B[1] == "B", dt1 &amp;lt;&amp;lt; New Column( "B", character, nominal );
		D();
		EE();
		F();
	, 
	dt1 &amp;lt;&amp;lt; New Column( "N/A", character, nominal )
);


// Second Example Column B has the value B
dt2 = New Table( "Example2",
	Add Rows( 1 ),
	New Column( "Column A", Character, "Nominal", Set Values( {""} ) ),
	New Column( "Column B", Character, "Nominal", Set Values( {"B"} ) )
);
Wait( 5 );

If(
	:Column A[1] == "A",
		dt2 &amp;lt;&amp;lt; New Column( "A", character, nominal );
		A();
		B();
		C();,
	:Column B[1] == "B", dt2 &amp;lt;&amp;lt; New Column( "B", character, nominal );
		D();
		EE();
		F();
	, 
	dt2 &amp;lt;&amp;lt; New Column( "N/A", character, nominal )
);


// Third Example Neither column A has and A nor Column B has a B
dt3 = New Table( "Example3",
	Add Rows( 1 ),
	New Column( "Column A", Character, "Nominal", Set Values( {""} ) ),
	New Column( "Column B", Character, "Nominal", Set Values( {""} ) )
);
Wait( 5 );

If(
	dt3:Column A[1] == "A",
		dt3 &amp;lt;&amp;lt; New Column( "A", character, nominal );
		A();
		B();
		C();,
	dt3:Column B[1] == "B", dt3 &amp;lt;&amp;lt; New Column( "B", character, nominal );
		D();
		EE();
		F();
	, 
	dt3 &amp;lt;&amp;lt; New Column( "N/A", character, nominal )
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It is my guess, that this is not what you want&lt;/P&gt;</description>
      <pubDate>Sat, 29 May 2021 02:02:52 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Help-with-If-Statement/m-p/389360#M63949</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-05-29T02:02:52Z</dc:date>
    </item>
    <item>
      <title>Re: Help with If Statement</title>
      <link>https://community.jmp.com/t5/Discussions/Help-with-If-Statement/m-p/389391#M63962</link>
      <description>&lt;P&gt;Good point about the column name changing. It makes it harder to write the JSL for subsequent processing. Probably you want the same column name for all the cases, something like "status" or "action type".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 29 May 2021 15:46:36 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Help-with-If-Statement/m-p/389391#M63962</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2021-05-29T15:46:36Z</dc:date>
    </item>
  </channel>
</rss>

