<?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: Use column variable in IF expression in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Use-column-variable-in-IF-expression/m-p/595251#M79895</link>
    <description>&lt;P&gt;A slight disadvantage of this code:&amp;nbsp;The variables in the Formula will not be defined anymore at a later time.&lt;BR /&gt;This can be seen by the red wiggles in the Formula Editor:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hogi_0-1675120612886.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/49659i03C6B6B0CCA1EB02/image-size/medium?v=v2&amp;amp;px=400" role="button" title="hogi_0-1675120612886.png" alt="hogi_0-1675120612886.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The result: When a value in the table changes in the future, the column will not be updated automatically.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A more robust code can be generated with an approach that I learned from &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;&amp;nbsp;:&lt;BR /&gt;Put &lt;STRONG&gt;NameExpr(As Column())&lt;/STRONG&gt; inside &lt;STRONG&gt;Expr()&lt;/STRONG&gt;.&lt;BR /&gt;Then the Formula will look like this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hogi_1-1675120833925.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/49660i6DBCC6AFE4E4032E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="hogi_1-1675120833925.png" alt="hogi_1-1675120833925.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;and column values will update in the future if input values get updated :)&lt;/img&gt;&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 = Open("$SAMPLE_DATA/Big Class.jmp");
colSelect ="age";
quantVal1 = 13;
quantVal2 = 16;

//Custom Quantiles amounts
Eval(Eval Expr(dt &amp;lt;&amp;lt; New Column( "Categories",
	Numeric, "Continuous",
	Format( "Best", 9 ),
	Formula(
		If( Expr( NameExpr(As Column(dt, colSelect)) )/*:Total Time From CheckIn Collector To Exit*/ &amp;lt;= Expr(quantVal1),
			1,
			If( Expr( Name Expr(As Column(dt, colSelect)) )/*:Total Time From CheckIn Collector To Exit*/ &amp;lt;= Expr(quantVal2),
				2,
				3
			)
		)
	),
	Set Property( "Value Order", {} ),
	Set Property(
		"Color Gradient",
		{{"Green to Orange to Red", 4099, {{0, 227, 0}, {255, 255, 0}, {252, 11, 11}}, {0, 0.5, 1}}, Range( {1, 3, 1} )}
	),
	Color Cell by Value,
	Set Display Width( 74 )
)));

dt:age[12]=40;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 30 Jan 2023 23:40:43 GMT</pubDate>
    <dc:creator>hogi</dc:creator>
    <dc:date>2023-01-30T23:40:43Z</dc:date>
    <item>
      <title>Use column variable in IF expression</title>
      <link>https://community.jmp.com/t5/Discussions/Use-column-variable-in-IF-expression/m-p/354981#M60487</link>
      <description>&lt;P&gt;Dear Cummunity,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below, I'm using several variables brought by a Dialog:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;colSelect: the column to be analyzed&lt;/LI&gt;&lt;LI&gt;quantVal1 &amp;amp;&amp;nbsp;quantVal2: Quantile values&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;In the following piece of script, I'm creating a "Categories" column, that will then be tabulated to obtain amounts for each quantile.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Two problems:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;replacing the hardcodedl column name with an Eval() method does not work&lt;/LI&gt;&lt;LI&gt;how could I test if the column already exists, and if yes, update its formula?&lt;BR /&gt;This would allow to refresh my whole analysis process with new column and quantiles, with out having to restart from scratch loading and processing the data table.&lt;/LI&gt;&lt;/OL&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;//Custom Quantiles amounts
dt &amp;lt;&amp;lt; New Column( "Categories",
	Numeric, "Continuous",
	Format( "Best", 9 ),
	Formula(
		If( Eval( colSelect )/*:Total Time From CheckIn Collector To Exit*/ &amp;lt;= quantVal1,
			1,
			If( Eval( colSelect )/*:Total Time From CheckIn Collector To Exit*/ &amp;lt;= quantVal2,
				2,
				3
			)
		)
	),
	Set Property( "Value Order", {} ),
	Set Property(
		"Color Gradient",
		{{"Green to Orange to Red", 4099, {{0, 227, 0}, {255, 255, 0}, {252, 11, 11}}, {0, 0.5, 1}}, Range( {1, 3, 1} )}
	),
	Color Cell by Value,
	Set Display Width( 74 )
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 22:04:49 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Use-column-variable-in-IF-expression/m-p/354981#M60487</guid>
      <dc:creator>HubP_SDe</dc:creator>
      <dc:date>2023-06-09T22:04:49Z</dc:date>
    </item>
    <item>
      <title>Re: Use column variable in IF expression</title>
      <link>https://community.jmp.com/t5/Discussions/Use-column-variable-in-IF-expression/m-p/355029#M60489</link>
      <description>&lt;P&gt;1. Good thread how to replace values in formula:&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.jmp.com/t5/JSL-Cookbook/Insert-one-expression-into-another-using-Eval-Insert-Eval-Expr/ta-p/48998" target="_blank" rel="noopener"&gt;Insert one expression into another using Eval Insert, Eval Expr, Parse, and Substitute&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you don't need formula I would suggest using &amp;lt;&amp;lt; Set Each Value.&lt;/P&gt;&lt;P&gt;2. You can get column name list with dt &amp;lt;&amp;lt; Get Column Names("String") and use Contains() to check for columns in that list&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This should work:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");
colSelect = 1;
quantVal1 = 1;
quantVal2 = 2;

//Custom Quantiles amounts
Eval(Eval Expr(dt &amp;lt;&amp;lt; New Column( "Categories",
	Numeric, "Continuous",
	Format( "Best", 9 ),
	Formula(
		If( Expr( colSelect )/*:Total Time From CheckIn Collector To Exit*/ &amp;lt;= Expr(quantVal1),
			1,
			If( Expr( colSelect )/*:Total Time From CheckIn Collector To Exit*/ &amp;lt;= Expr(quantVal2),
				2,
				3
			)
		)
	),
	Set Property( "Value Order", {} ),
	Set Property(
		"Color Gradient",
		{{"Green to Orange to Red", 4099, {{0, 227, 0}, {255, 255, 0}, {252, 11, 11}}, {0, 0.5, 1}}, Range( {1, 3, 1} )}
	),
	Color Cell by Value,
	Set Display Width( 74 )
)));
colList = dt &amp;lt;&amp;lt; Get Column Names("String");
Show(Contains(colList, "Categories")); //will return index&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2021 14:17:05 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Use-column-variable-in-IF-expression/m-p/355029#M60489</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2021-02-02T14:17:05Z</dc:date>
    </item>
    <item>
      <title>Re: Use column variable in IF expression</title>
      <link>https://community.jmp.com/t5/Discussions/Use-column-variable-in-IF-expression/m-p/355044#M60491</link>
      <description>&lt;P&gt;since ColSelect is coming from a dialog, it may in fact be a list of one item.&lt;/P&gt;
&lt;P&gt;If you evaluate ColSelect, what is returned? if it is {:colname}, then it is a list of one item&lt;/P&gt;
&lt;P&gt;Try evaluating ColSelect[1], if it is from a list then :colname will be returned.&lt;/P&gt;
&lt;P&gt;In this case eval() returns the list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;take a look at Eval list() too&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;there is a pdf that is SUPER helpful for understanding expressions attached to this post.&lt;/P&gt;
&lt;P&gt;&lt;LI-MESSAGE title="Expression Handling Functions: Part I - Unraveling the Expr(), NameExpr(), Eval(), ... Conundrum" uid="28963" url="https://community.jmp.com/t5/JMPer-Cable/Expression-Handling-Functions-Part-I-Unraveling-the-Expr/m-p/28963#U28963" 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;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 12:55:00 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Use-column-variable-in-IF-expression/m-p/355044#M60491</guid>
      <dc:creator>Byron_JMP</dc:creator>
      <dc:date>2021-02-03T12:55:00Z</dc:date>
    </item>
    <item>
      <title>Re: Use column variable in IF expression</title>
      <link>https://community.jmp.com/t5/Discussions/Use-column-variable-in-IF-expression/m-p/355079#M60499</link>
      <description>Hi Byron,&lt;BR /&gt;&lt;BR /&gt;The Show(colSelect) returns a simple string, not a list (I took care of this when passing the Dialog arguments):&lt;BR /&gt;colSelect = "Total Time From Check-In To Exit";&lt;BR /&gt;&lt;BR /&gt;I will explore this PDF, Thanks</description>
      <pubDate>Tue, 02 Feb 2021 15:52:17 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Use-column-variable-in-IF-expression/m-p/355079#M60499</guid>
      <dc:creator>HubP_SDe</dc:creator>
      <dc:date>2021-02-02T15:52:17Z</dc:date>
    </item>
    <item>
      <title>Re: Use column variable in IF expression</title>
      <link>https://community.jmp.com/t5/Discussions/Use-column-variable-in-IF-expression/m-p/355087#M60501</link>
      <description>&lt;P&gt;Thanks a lot Jarmo,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have partial solutions in your reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Still, the colSelect trick only works with a given numeric value, not a column name (forgot to mention)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks to your example, here is more what it would look like (Expr (colSelect) not working in this updated context):&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 = Open("$SAMPLE_DATA/Big Class.jmp");
colSelect = "age";
quantVal1 = 13;
quantVal2 = 16;

//Custom Quantiles amounts
Eval(Eval Expr(dt &amp;lt;&amp;lt; New Column( "Categories",
	Numeric, "Continuous",
	Format( "Best", 9 ),
	Formula(
		If( /*Expr( colSelect )*/:age &amp;lt;= quantVal1,
			1,
			If( /*Expr( colSelect )*/:age &amp;lt;= quantVal2,
				2,
				3
			)
		)
	),
	Set Property( "Value Order", {} ),
	Set Property(
		"Color Gradient",
		{{"Green to Orange to Red", 4099, {{0, 227, 0}, {255, 255, 0}, {252, 11, 11}}, {0, 0.5, 1}}, Range( {1, 3, 1} )}
	),
	Color Cell by Value,
	Set Display Width( 74 )
)));
colList = dt &amp;lt;&amp;lt; Get Column Names("String");
Show(Contains(colList, "Categories")); //will return index&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2021 16:05:38 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Use-column-variable-in-IF-expression/m-p/355087#M60501</guid>
      <dc:creator>HubP_SDe</dc:creator>
      <dc:date>2021-02-02T16:05:38Z</dc:date>
    </item>
    <item>
      <title>Re: Use column variable in IF expression</title>
      <link>https://community.jmp.com/t5/Discussions/Use-column-variable-in-IF-expression/m-p/355092#M60503</link>
      <description>&lt;P&gt;maybe also look at these two arguments also:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Column()&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;As name()&lt;/P&gt;
&lt;P&gt;you script might be trying to parse ColSelect as a text string rather than a column name&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2021 16:12:30 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Use-column-variable-in-IF-expression/m-p/355092#M60503</guid>
      <dc:creator>Byron_JMP</dc:creator>
      <dc:date>2021-02-02T16:12:30Z</dc:date>
    </item>
    <item>
      <title>Re: Use column variable in IF expression</title>
      <link>https://community.jmp.com/t5/Discussions/Use-column-variable-in-IF-expression/m-p/355099#M60504</link>
      <description>&lt;P&gt;Thanks again Byron,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After trying both, and reading some of the links provided, it was finally a mix of both whihc worked: AsColumn()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks all!&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");
colSelect = "age";
quantVal1 = 13;
quantVal2 = 16;

//Custom Quantiles amounts
Eval(Eval Expr(dt &amp;lt;&amp;lt; New Column( "Categories",
	Numeric, "Continuous",
	Format( "Best", 9 ),
	Formula(
		If( AsColumn( colSelect )/*:age*/ &amp;lt;= quantVal1,
			1,
			If( AsColumn( colSelect )/*:age*/ &amp;lt;= quantVal2,
				2,
				3
			)
		)
	),
	Set Property( "Value Order", {} ),
	Set Property(
		"Color Gradient",
		{{"Green to Orange to Red", 4099, {{0, 227, 0}, {255, 255, 0}, {252, 11, 11}}, {0, 0.5, 1}}, Range( {1, 3, 1} )}
	),
	Color Cell by Value,
	Set Display Width( 74 )
)));
colList = dt &amp;lt;&amp;lt; Get Column Names("String");
Show(Contains(colList, "Categories")); //will return index&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Feb 2021 16:21:28 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Use-column-variable-in-IF-expression/m-p/355099#M60504</guid>
      <dc:creator>HubP_SDe</dc:creator>
      <dc:date>2021-02-02T16:21:28Z</dc:date>
    </item>
    <item>
      <title>Re: Use column variable in IF expression</title>
      <link>https://community.jmp.com/t5/Discussions/Use-column-variable-in-IF-expression/m-p/595251#M79895</link>
      <description>&lt;P&gt;A slight disadvantage of this code:&amp;nbsp;The variables in the Formula will not be defined anymore at a later time.&lt;BR /&gt;This can be seen by the red wiggles in the Formula Editor:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hogi_0-1675120612886.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/49659i03C6B6B0CCA1EB02/image-size/medium?v=v2&amp;amp;px=400" role="button" title="hogi_0-1675120612886.png" alt="hogi_0-1675120612886.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The result: When a value in the table changes in the future, the column will not be updated automatically.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A more robust code can be generated with an approach that I learned from &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;&amp;nbsp;:&lt;BR /&gt;Put &lt;STRONG&gt;NameExpr(As Column())&lt;/STRONG&gt; inside &lt;STRONG&gt;Expr()&lt;/STRONG&gt;.&lt;BR /&gt;Then the Formula will look like this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hogi_1-1675120833925.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/49660i6DBCC6AFE4E4032E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="hogi_1-1675120833925.png" alt="hogi_1-1675120833925.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;and column values will update in the future if input values get updated :)&lt;/img&gt;&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 = Open("$SAMPLE_DATA/Big Class.jmp");
colSelect ="age";
quantVal1 = 13;
quantVal2 = 16;

//Custom Quantiles amounts
Eval(Eval Expr(dt &amp;lt;&amp;lt; New Column( "Categories",
	Numeric, "Continuous",
	Format( "Best", 9 ),
	Formula(
		If( Expr( NameExpr(As Column(dt, colSelect)) )/*:Total Time From CheckIn Collector To Exit*/ &amp;lt;= Expr(quantVal1),
			1,
			If( Expr( Name Expr(As Column(dt, colSelect)) )/*:Total Time From CheckIn Collector To Exit*/ &amp;lt;= Expr(quantVal2),
				2,
				3
			)
		)
	),
	Set Property( "Value Order", {} ),
	Set Property(
		"Color Gradient",
		{{"Green to Orange to Red", 4099, {{0, 227, 0}, {255, 255, 0}, {252, 11, 11}}, {0, 0.5, 1}}, Range( {1, 3, 1} )}
	),
	Color Cell by Value,
	Set Display Width( 74 )
)));

dt:age[12]=40;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jan 2023 23:40:43 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Use-column-variable-in-IF-expression/m-p/595251#M79895</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2023-01-30T23:40:43Z</dc:date>
    </item>
  </channel>
</rss>

