<?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: JSL script to create or condition by looping thorough column names in a list in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/JSL-script-to-create-or-condition-by-looping-thorough-column/m-p/622489#M82143</link>
    <description>&lt;P&gt;Building this using strings is most likely most simple option as the expression is quite simple one. But... I don't like using Eval(Parse()) so here are few options which are not using that (second option might not do what you want with missing values)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = New Table("Untitled 3",
	Add Rows(0),
	Compress File When Saved(1),
	New Column("a", Numeric, "Continuous", Format("Best", 12), Set Values([0,1])),
	New Column("b", Numeric, "Continuous", Format("Best", 12), Set Values([0,0])),
	New Column("c", Numeric, "Continuous", Format("Best", 12), Set Values([0,0]))
);
input_col_list = {"a", "b", "c"};
x = 0.1;

// using Or
or_expr = Expr(Or());
// https://community.jmp.com/t5/JSL-Cookbook-Archived/Insert-one-expression-into-another-using-Eval-Insert-Eval-Expr/ta-p/48998
For Each({col_name}, input_col_list,
	col_expr = Substitute(
		expr(_col_ref_ &amp;gt;= _comparison_value_),
		Expr(_col_ref_), NameExpr(AsColumn(Column(dt, col_name))),
		Expr(_comparison_value_), x
	);
	Insert Into(or_expr, Name Expr(col_expr));
);
// Show(name expr(or_expr));
Eval(EvalExpr(dt &amp;lt;&amp;lt; New Column("d", Numeric, Continuous, Formula(
	If(Expr(name expr(or_expr)), 1, 0)
))));


// using matrix and any
col_refs = Transform Each({col_name}, input_col_list,
	Name Expr(As Column(Column(dt, col_name)));
);
Eval(EvalExpr(dt &amp;lt;&amp;lt; New Column("d", Numeric, Continuous, Formula(
	Any(Matrix(Expr(col_refs)) &amp;gt;= Expr(x))
))));


// function of second option
create_check_col = function({dt, col_input, limit_val}, {Default Local},
	col_refs = Transform Each({col_name}, col_input,
		Name Expr(As Column(Column(dt, col_name)));
	);
	
	new_col = Eval(EvalExpr(dt &amp;lt;&amp;lt; New Column("d", Numeric, Continuous, Formula(
		Any(Matrix(Expr(col_refs)) &amp;gt;= Expr(limit_val))
	))));
	
	return(new_col);
);
create_check_col(dt, input_col_list, x);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 14 Apr 2023 05:40:55 GMT</pubDate>
    <dc:creator>jthi</dc:creator>
    <dc:date>2023-04-14T05:40:55Z</dc:date>
    <item>
      <title>JSL script to create or condition by looping thorough column names in a list</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-script-to-create-or-condition-by-looping-thorough-column/m-p/622464#M82140</link>
      <description>&lt;P&gt;I'd like to create a function in jsl that takes a given list of column names as input, uses those columns to do a OR condition, and outputs a column with that looping OR formula. How do U do that?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;input_col_list = { "a", "b", "c"};
input_dt = dt;
x = 0.1;
input_dt &amp;lt;&amp;lt; New Column("d", numeric, continuous, 
formula ( 
If(
(As Column("a") &amp;gt;= x  |  As Column("b") &amp;gt;= x  | As Column("c") &amp;gt;=  x), 
1,
0
) 
));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;For above, I would like to make a function like below:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;my_func =
Function(
{input_dt, input_col_list, x},
{//local var},
// function body
...
Return As column("d")
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Jun 2023 16:07:54 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-script-to-create-or-condition-by-looping-thorough-column/m-p/622464#M82140</guid>
      <dc:creator>OrdinaryParrot2</dc:creator>
      <dc:date>2023-06-09T16:07:54Z</dc:date>
    </item>
    <item>
      <title>Re: JSL script to create or condition by looping thorough column names in a list</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-script-to-create-or-condition-by-looping-thorough-column/m-p/622488#M82142</link>
      <description>&lt;P&gt;Here is an example of one way to do it.......others may have more eloquent ways&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = 
// Open Data Table: Big Class.jmp
// → Data Table( "Big Class" )
Open( "$SAMPLE_DATA/Big Class.jmp" );

my_func = Function( {input_dt, input_col_list, x},
	{input_dt, input_col_list, x, the_cmd},
	input_dt &amp;lt;&amp;lt; New Column( "d" );
	current data table(input_dt);
	the_cmd = "current data table():d &amp;lt;&amp;lt; set formula( If(  current data table():\!"" ||
	Char( input_col_list[1] ) || "\!"n &amp;gt;= " || Char( x );
	For( i = 2, i &amp;lt;= N Items( input_col_list ), i++,
		the_cmd = the_cmd || " | current data table():\!"" || Char( input_col_list[i] ) || "\!"n &amp;gt;= "
		 || Char( x )
	);
	the_cmd = the_cmd || ", 1, 0) );";
	Eval( Parse( the_cmd ) );
);

input_col_listx = {"Height", weight};
dtx = Data Table( "big class" );
xx = 101;

theReturn = my_func( dtx, input_col_listx, xx );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Apr 2023 05:36:44 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-script-to-create-or-condition-by-looping-thorough-column/m-p/622488#M82142</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2023-04-14T05:36:44Z</dc:date>
    </item>
    <item>
      <title>Re: JSL script to create or condition by looping thorough column names in a list</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-script-to-create-or-condition-by-looping-thorough-column/m-p/622489#M82143</link>
      <description>&lt;P&gt;Building this using strings is most likely most simple option as the expression is quite simple one. But... I don't like using Eval(Parse()) so here are few options which are not using that (second option might not do what you want with missing values)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = New Table("Untitled 3",
	Add Rows(0),
	Compress File When Saved(1),
	New Column("a", Numeric, "Continuous", Format("Best", 12), Set Values([0,1])),
	New Column("b", Numeric, "Continuous", Format("Best", 12), Set Values([0,0])),
	New Column("c", Numeric, "Continuous", Format("Best", 12), Set Values([0,0]))
);
input_col_list = {"a", "b", "c"};
x = 0.1;

// using Or
or_expr = Expr(Or());
// https://community.jmp.com/t5/JSL-Cookbook-Archived/Insert-one-expression-into-another-using-Eval-Insert-Eval-Expr/ta-p/48998
For Each({col_name}, input_col_list,
	col_expr = Substitute(
		expr(_col_ref_ &amp;gt;= _comparison_value_),
		Expr(_col_ref_), NameExpr(AsColumn(Column(dt, col_name))),
		Expr(_comparison_value_), x
	);
	Insert Into(or_expr, Name Expr(col_expr));
);
// Show(name expr(or_expr));
Eval(EvalExpr(dt &amp;lt;&amp;lt; New Column("d", Numeric, Continuous, Formula(
	If(Expr(name expr(or_expr)), 1, 0)
))));


// using matrix and any
col_refs = Transform Each({col_name}, input_col_list,
	Name Expr(As Column(Column(dt, col_name)));
);
Eval(EvalExpr(dt &amp;lt;&amp;lt; New Column("d", Numeric, Continuous, Formula(
	Any(Matrix(Expr(col_refs)) &amp;gt;= Expr(x))
))));


// function of second option
create_check_col = function({dt, col_input, limit_val}, {Default Local},
	col_refs = Transform Each({col_name}, col_input,
		Name Expr(As Column(Column(dt, col_name)));
	);
	
	new_col = Eval(EvalExpr(dt &amp;lt;&amp;lt; New Column("d", Numeric, Continuous, Formula(
		Any(Matrix(Expr(col_refs)) &amp;gt;= Expr(limit_val))
	))));
	
	return(new_col);
);
create_check_col(dt, input_col_list, x);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 14 Apr 2023 05:40:55 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-script-to-create-or-condition-by-looping-thorough-column/m-p/622489#M82143</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-04-14T05:40:55Z</dc:date>
    </item>
  </channel>
</rss>

