<?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 of parameters in 'select where' and 'name selection in column' in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/use-of-parameters-in-select-where-and-name-selection-in-column/m-p/388277#M63839</link>
    <description>&lt;P&gt;Thank you very much. The code is very compact and worked.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 25 May 2021 18:07:36 GMT</pubDate>
    <dc:creator>MFVIT</dc:creator>
    <dc:date>2021-05-25T18:07:36Z</dc:date>
    <item>
      <title>use of parameters in 'select where' and 'name selection in column'</title>
      <link>https://community.jmp.com/t5/Discussions/use-of-parameters-in-select-where-and-name-selection-in-column/m-p/388205#M63831</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I need to take a data table made up of two columns, X and Y, select several rows of the data table and name the selection. This corresponds to select twenty rectangles in the x-y cartesian space and name them with a number (from 1 to 20) (I am working with an image).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I wrote a script but it does not work. I think I need to solve two problems: 1) how can I use a parameter, see X1, X2, .., in the argument of 'select where'? 2) how can I use a parameter, see n_patch, in the argument of 'name selection in column'?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the script:&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();
X0 = 2332;
Y0 = 558;

n_patch = 0;
delta_x = 100;
delta_y = 100;
dist_y = 488;
dist_x = 656;
L_x = 500;
L_y = 500;
For( n_x = 1, n_x &amp;lt;= 4, n_x++,
	For( n_y = 1, n_y &amp;lt;= 5, n_y++,
		Xc = X0 - (n_x - 1) * (dist_x) + L_x / 2;
		Yc = Y0 + (n_y - 1) * (dist_y) + L_y / 2;
		n_patch = n_patch + 1;
		X1 = Xc - delta_x;
		X2 = Xc + delta_x;
		Y1 = Yc - delta_y;
		Y2 = Yc + delta_y;
		dt &amp;lt;&amp;lt; Row Selection(
			Select where( (:X &amp;gt;= X1 &amp;amp; :X &amp;lt;= X2) &amp;amp; (Y &amp;gt;= Y1 &amp;amp; Y &amp;lt;= Y2) )
		);

		dt &amp;lt;&amp;lt; Name Selection in Column(
			Column Name( "Patch#" ),
			Selected( ("n_patch") ),
			Unselected( "" )
		);
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:30:41 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/use-of-parameters-in-select-where-and-name-selection-in-column/m-p/388205#M63831</guid>
      <dc:creator>MFVIT</dc:creator>
      <dc:date>2023-06-10T23:30:41Z</dc:date>
    </item>
    <item>
      <title>Re: use of parameters in 'select where' and 'name selection in column'</title>
      <link>https://community.jmp.com/t5/Discussions/use-of-parameters-in-select-where-and-name-selection-in-column/m-p/388237#M63833</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/4199"&gt;@MFVIT&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to make sure the values of X1 and Y1 are evaluated in your script, rather than looking for something in the data table itself.&amp;nbsp; This problem is illustrated in&amp;nbsp;&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;. You can ensure this happens by using Eval( Eval Expr( ) ). Here is an example using your code with an example data table.&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 = New Table( "Example Data",
	Add Rows( 10000 ),
	New Column( "X", Numeric, "Continuous", Format( "Best", 12 ),
		Formula( Random Uniform( 0, 10000 ) ) ),
	New Column( "Y", Numeric, "Continuous", Format( "Best", 12 ),
		Formula( Random Uniform( 0, 10000 ) ) )
);

X0 = 2332;
Y0 = 558;

n_patch = 0;
delta_x = 100;
delta_y = 100;
dist_y = 488;
dist_x = 656;
L_x = 500;
L_y = 500;

For( n_x = 1, n_x &amp;lt;= 4, n_x++,
	For( n_y = 1, n_y &amp;lt;= 5, n_y++,
		Xc = X0 - (n_x - 1) * (dist_x) + L_x / 2;
		Yc = Y0 + (n_y - 1) * (dist_y) + L_y / 2;
		n_patch = n_patch + 1;
		X1 = Xc - delta_x;
		X2 = Xc + delta_x;
		Y1 = Yc - delta_y;
		Y2 = Yc + delta_y;
		Eval( Eval Expr(
			dt &amp;lt;&amp;lt; Row Selection(
				Select where( (:X &amp;gt;= Expr( X1 ) &amp;amp; :X &amp;lt;= Expr( X2 )) &amp;amp; (:Y &amp;gt;= Expr( Y1 ) &amp;amp; :Y &amp;lt;= Expr( Y2 ) ) )
			);
		) );
		dt &amp;lt;&amp;lt; run formulas;
		dt &amp;lt;&amp;lt; Name Selection in Column(
			Column Name( "Patch#" || char( n_patch ) ),
			Selected( "n_patch = " || char( n_patch ) ),
			Unselected( "" )
		);
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 May 2021 15:55:36 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/use-of-parameters-in-select-where-and-name-selection-in-column/m-p/388237#M63833</guid>
      <dc:creator>ih</dc:creator>
      <dc:date>2021-05-25T15:55:36Z</dc:date>
    </item>
    <item>
      <title>Re: use of parameters in 'select where' and 'name selection in column'</title>
      <link>https://community.jmp.com/t5/Discussions/use-of-parameters-in-select-where-and-name-selection-in-column/m-p/388241#M63834</link>
      <description>&lt;P&gt;Hello, thank your very much for your prompt reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your code is very useful to me, I think I am on the right way. However, there is still something that does not work.&lt;/P&gt;&lt;P&gt;I tried to run your code and I saw that it adds many column with names 'Patch#1', 'Patch#2', etc. so I changed the line&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="jsl"&gt;Column Name( "Patch#" || char( n_patch ) )&lt;/LI-CODE&gt;&lt;P&gt;with&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Column Name( "Patch#")&lt;/LI-CODE&gt;&lt;P&gt;because I want just one column with the name Patch#.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But the code does not select what I expect to be selected. It selects only patch5, 10, 15 and 20 and not the other patches and furthermore the selected rows do not correspond to patches..&lt;/P&gt;&lt;P&gt;So, I am not sure the selection command is working correctly.&lt;/P&gt;&lt;P&gt;Many thanks for any help.&lt;/P&gt;&lt;P&gt;Marcello.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 May 2021 16:36:18 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/use-of-parameters-in-select-where-and-name-selection-in-column/m-p/388241#M63834</guid>
      <dc:creator>MFVIT</dc:creator>
      <dc:date>2021-05-25T16:36:18Z</dc:date>
    </item>
    <item>
      <title>Re: use of parameters in 'select where' and 'name selection in column'</title>
      <link>https://community.jmp.com/t5/Discussions/use-of-parameters-in-select-where-and-name-selection-in-column/m-p/388242#M63835</link>
      <description>&lt;P&gt;You might be using a bit older version of JMP so I'm not sure if these will work for you (not using Row Selection or Name Selection in column).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can get rows of interest with &amp;lt;&amp;lt; get rows where and then set values with column()[rows]&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt &amp;lt;&amp;lt; New Column("Patch#", Character);
For( n_x = 1, n_x &amp;lt;= 4, n_x++,
	For( n_y = 1, n_y &amp;lt;= 5, n_y++,
		Xc = X0 - (n_x - 1) * (dist_x) + L_x / 2;
		Yc = Y0 + (n_y - 1) * (dist_y) + L_y / 2;
		n_patch = n_patch + 1;
		X1 = Xc - delta_x;
		X2 = Xc + delta_x;
		Y1 = Yc - delta_y;
		Y2 = Yc + delta_y;
		wantedRows = dt &amp;lt;&amp;lt; get rows where(:X &amp;gt;= X1 &amp;amp; :X &amp;lt;= X2 &amp;amp; :Y &amp;gt;= Y1 &amp;amp; :Y &amp;lt;= Y2);
		Column(dt, "Patch#")[wantedRows] = char(n_patch);
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 May 2021 16:52:42 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/use-of-parameters-in-select-where-and-name-selection-in-column/m-p/388242#M63835</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2021-05-25T16:52:42Z</dc:date>
    </item>
    <item>
      <title>Re: use of parameters in 'select where' and 'name selection in column'</title>
      <link>https://community.jmp.com/t5/Discussions/use-of-parameters-in-select-where-and-name-selection-in-column/m-p/388277#M63839</link>
      <description>&lt;P&gt;Thank you very much. The code is very compact and worked.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 May 2021 18:07:36 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/use-of-parameters-in-select-where-and-name-selection-in-column/m-p/388277#M63839</guid>
      <dc:creator>MFVIT</dc:creator>
      <dc:date>2021-05-25T18:07:36Z</dc:date>
    </item>
  </channel>
</rss>

