<?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: Using Expr() and Eval() with variables name inside a loop in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Using-Expr-and-Eval-with-variables-name-inside-a-loop/m-p/735243#M91642</link>
    <description>&lt;P&gt;I believe this will work for you&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;x = Eval Expr(
			dis = dt &amp;lt;&amp;lt; Distribution(
					Continuous Distribution( Column( Expr(MetricCols[i] ))),
				Where(as column(SplitBy) == Expr(ColumnSplitBy[j])))
			);	&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 16 Mar 2024 00:38:33 GMT</pubDate>
    <dc:creator>txnelson</dc:creator>
    <dc:date>2024-03-16T00:38:33Z</dc:date>
    <item>
      <title>Using Expr() and Eval() with variables name inside a loop</title>
      <link>https://community.jmp.com/t5/Discussions/Using-Expr-and-Eval-with-variables-name-inside-a-loop/m-p/735241#M91641</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to plot distributions with a loop based on the following criteria:&lt;/P&gt;&lt;P&gt;- need to plot only columns with at least 1x spec limit (LSL or USL)&lt;/P&gt;&lt;P&gt;- need to split by arguments form a selected column (SplitBy)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used Eval(EvalExpr()) to build the expression that I need, but I am struggling with the Where() function to split by the selected column.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I extracted the part of the code that is failing and added a dummy table creation at the beginning so the issue can be replicated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;there are 3 options of my trials that can be commented/uncommented to replicate the issue in the code below.&lt;/P&gt;&lt;P&gt;My goal is to build an expression that properly calls for the variable "SplitBy" in the Where() like in Option 1 below (but ":CONFIG1" is hardcoded in Option 1)&lt;/P&gt;&lt;P&gt;my attempts Option 2 and 3 (among others...) are failing (log extracts below)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Option 1:
dis = dt &amp;lt;&amp;lt; Distribution(Continuous Distribution(Column("LogNormal 10,1"n)), Where(:CONFIG1 == “1"))

Option 2:
dis = dt &amp;lt;&amp;lt; Distribution(Continuous Distribution(Column("LogNormal 10,1"n)), Where(Column("CONFIG1") == "1"))
This Where-clause for data table 'tabletest.jmp' resulted in no rows: Column( "CONFIG1" ) == "1"

Option 3:
dis = dt &amp;lt;&amp;lt; Distribution(Continuous Distribution(Column("LogNormal 10,1"n)), Where(":CONFIG1" == "1"))
This Where-clause for data table 'tabletest.jmp' resulted in no rows: ":CONFIG1" == “1"&lt;/PRE&gt;&lt;P&gt;I know the expression evaluation is a recurring topic in this forum, but I spent a lot of time trying to make it work and still no success :\&lt;/img&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot in advance&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Voiz&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 );
clear symbols();
Deletesymbols();

//Create table with random distribution 
dt = New Table( "tabletest",
	Add Rows( 150 ),
	New Column( "LogNormal 10,1", Numeric, "Continuous", formula( Random Lognormal( 10, 1 ) ) ),
	New Column( "Normal 10,1", Numeric, "Continuous", formula( Random Normal( 10, 1 ) ) ),
	New Column( "Gamma 10,1", Numeric, "Continuous", formula( Random Gamma( 10, 1 ) ) ),
	New Column( "Normal 10,2", Numeric, "Continuous", formula( Random Gamma( 10, 2 ) ) ),
	New Column( "CONFIG1", Character, "Nominal", formula(char(Random Integer( 1, 3 )))),
	New Column( "CONFIG2", Character, "Nominal", formula(char(Random Integer( 1, 3 ))));
	
);
Column( dt, "LogNormal 10,1" ) &amp;lt;&amp;lt; set property( "spec limits", {LSL( 0 ), USL( 400000 ), Show Limits( 0 )} );
Column( dt, "Normal 10,1" ) &amp;lt;&amp;lt; set property( "spec limits", {LSL( 6 ), USL( 14 ), Show Limits( 0 )} );
Column( dt, "Gamma 10,1" ) &amp;lt;&amp;lt; set property( "spec limits", {LSL( 0 ), USL( 40 ), Show Limits( 0 )} );

dt &amp;lt;&amp;lt; save( "$Desktop\tabletest.jmp" );

SplitBy = "CONFIG1";

//Get a list from all unique configs
summarize(ColumnSplitBy=by(Column (SplitBy)));
show(ColumnSplitBy);
For( i = N Items( ColumnSplitBy ), i &amp;gt; 0, i--,
  If( ColumnSplitBy[i] == "",
  Remove From( ColumnSplitBy, i, 1 );
  )
);

//Get Column only with limits (At east LSL or USL, I don't care about target)
MetricCols = dt &amp;lt;&amp;lt; Get Column Names( numeric, continuous );

Show( MetricCols );

For( i = N Items( MetricCols ), i &amp;gt;= 1, i--, 

	Q = Column( MetricCols[i] ) &amp;lt;&amp;lt; Get Property( "Spec limits" );
	Show( Q );

	spec_x = Eval List( {Arg( Q, 1 )/*, Arg( Q, 2 ), Arg( Q, 3 )*/} );
	Show( spec_x );
	If( N Row( Loc( spec_x, Empty() ) ),
		Remove From( MetricCols, i )
	);
);
 
k=1;
//Loop to run through all configs
For ( j = 1, j &amp;lt;= N Items( ColumnSplitBy ), j++,
Show( j );

//Loop to run Distribution &amp;gt; Fit ALL &amp;gt; Capability and collect the stats
	For( i = 1, i &amp;lt;= N Items( MetricCols ), i++,
		Show( i );
	
		////////////////////////////////////////////////////// Option 1: That works well, but :CONFIG1 is hardcoded
		x = Eval Expr(
			dis = dt &amp;lt;&amp;lt; Distribution(
					Continuous Distribution( Column( Expr(MetricCols[i] ))),
				Where(:CONFIG1 == Expr(ColumnSplitBy[j])))
			);		
			
		print (x);
		Eval (x);
		
/*		////////////////////////////////////////////////////// Option 2 : That doesn't work 
		x = Eval Expr(
			dis = dt &amp;lt;&amp;lt; Distribution(
					Continuous Distribution( Column( Expr(MetricCols[i] ))),
				Where(Expr(Column(SplitBy)) == Expr(ColumnSplitBy[j])))
			);		
			
		print (x);
		Eval (x);		*/
		
/*		////////////////////////////////////////////////////// Option 3 : That doesn't work 
		x = Eval Expr(
			dis = dt &amp;lt;&amp;lt; Distribution(
					Continuous Distribution( Column( Expr(MetricCols[i] ))),
				Where(Expr(":"||SplitBy) == Expr(ColumnSplitBy[j])))
			);		
			
		print (x);
		Eval (x);		*/	
	
	);
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 16 Mar 2024 00:00:49 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Using-Expr-and-Eval-with-variables-name-inside-a-loop/m-p/735241#M91641</guid>
      <dc:creator>Voizingu</dc:creator>
      <dc:date>2024-03-16T00:00:49Z</dc:date>
    </item>
    <item>
      <title>Re: Using Expr() and Eval() with variables name inside a loop</title>
      <link>https://community.jmp.com/t5/Discussions/Using-Expr-and-Eval-with-variables-name-inside-a-loop/m-p/735243#M91642</link>
      <description>&lt;P&gt;I believe this will work for you&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;x = Eval Expr(
			dis = dt &amp;lt;&amp;lt; Distribution(
					Continuous Distribution( Column( Expr(MetricCols[i] ))),
				Where(as column(SplitBy) == Expr(ColumnSplitBy[j])))
			);	&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 16 Mar 2024 00:38:33 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Using-Expr-and-Eval-with-variables-name-inside-a-loop/m-p/735243#M91642</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2024-03-16T00:38:33Z</dc:date>
    </item>
    <item>
      <title>Re: Using Expr() and Eval() with variables name inside a loop</title>
      <link>https://community.jmp.com/t5/Discussions/Using-Expr-and-Eval-with-variables-name-inside-a-loop/m-p/735244#M91643</link>
      <description>&lt;P&gt;That works!!&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks so much Jim!&lt;/P&gt;</description>
      <pubDate>Sat, 16 Mar 2024 01:20:02 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Using-Expr-and-Eval-with-variables-name-inside-a-loop/m-p/735244#M91643</guid>
      <dc:creator>Voizingu</dc:creator>
      <dc:date>2024-03-16T01:20:02Z</dc:date>
    </item>
  </channel>
</rss>

