<?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 Declaring a variable inside a column formula in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Declaring-a-variable-inside-a-column-formula/m-p/765189#M97915</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Is it good practice to declare a variable inside a column formula? Or does this create risk of errors? My formula works well, but I'm concerned that it might be unreliable.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;rownum = Row();
If( :Measurement type == "STUDY_VARIABLE",
	:Control means[Min(
		Current Data Table() &amp;lt;&amp;lt; get rows where( :Measurement type == "STUDY_CONTROL" &amp;amp; :Control group == :Control group[rownum] )
	)],
	:Control means
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The setup is as follows:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;:Measurement type is a column which labels each row as either STUDY_CONTROL or STUDY_VARIABLE&lt;/LI&gt;&lt;LI&gt;:Control group is a column which uses a label (just a letter) to associate rows which are STUDY_VARIABLES with the appropriate mean (:Control means) of the relevant STUDY_CONTROL rows&lt;/LI&gt;&lt;LI&gt;:Control group[Row()] didn't work, so I specified the rownum variable up front&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Is this an elegant solution or a dangerous hack?&lt;/P&gt;&lt;P&gt;As a second question, the editor warns me that it's dangerous to use Current Data Table() in a formula - is there a better alternative?&lt;/P&gt;&lt;P&gt;Many thanks for any assistance - this is my first question!&lt;/P&gt;&lt;P&gt;David&lt;/P&gt;</description>
    <pubDate>Wed, 12 Jun 2024 17:40:03 GMT</pubDate>
    <dc:creator>Asterix</dc:creator>
    <dc:date>2024-06-12T17:40:03Z</dc:date>
    <item>
      <title>Declaring a variable inside a column formula</title>
      <link>https://community.jmp.com/t5/Discussions/Declaring-a-variable-inside-a-column-formula/m-p/765189#M97915</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Is it good practice to declare a variable inside a column formula? Or does this create risk of errors? My formula works well, but I'm concerned that it might be unreliable.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;rownum = Row();
If( :Measurement type == "STUDY_VARIABLE",
	:Control means[Min(
		Current Data Table() &amp;lt;&amp;lt; get rows where( :Measurement type == "STUDY_CONTROL" &amp;amp; :Control group == :Control group[rownum] )
	)],
	:Control means
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The setup is as follows:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;:Measurement type is a column which labels each row as either STUDY_CONTROL or STUDY_VARIABLE&lt;/LI&gt;&lt;LI&gt;:Control group is a column which uses a label (just a letter) to associate rows which are STUDY_VARIABLES with the appropriate mean (:Control means) of the relevant STUDY_CONTROL rows&lt;/LI&gt;&lt;LI&gt;:Control group[Row()] didn't work, so I specified the rownum variable up front&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Is this an elegant solution or a dangerous hack?&lt;/P&gt;&lt;P&gt;As a second question, the editor warns me that it's dangerous to use Current Data Table() in a formula - is there a better alternative?&lt;/P&gt;&lt;P&gt;Many thanks for any assistance - this is my first question!&lt;/P&gt;&lt;P&gt;David&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2024 17:40:03 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Declaring-a-variable-inside-a-column-formula/m-p/765189#M97915</guid>
      <dc:creator>Asterix</dc:creator>
      <dc:date>2024-06-12T17:40:03Z</dc:date>
    </item>
    <item>
      <title>Re: Declaring a variable inside a column formula</title>
      <link>https://community.jmp.com/t5/Discussions/Declaring-a-variable-inside-a-column-formula/m-p/802726#M97935</link>
      <description>&lt;P&gt;Welcome to the club!:)&lt;/img&gt;:)&lt;/img&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regarding your question on 'Current Data Table()', here a screenshot from the shared script in&amp;nbsp;&lt;LI-MESSAGE title="Scripters Club Recording: Building Robust and fail-safe scripts:" uid="788286" url="https://community.jmp.com/t5/JMP-Scripters-Club-Discussions/Scripters-Club-Recording-Building-Robust-and-fail-safe-scripts/m-p/788286#U788286" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-forum-thread lia-fa-icon lia-fa-forum lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ressel_0-1727703983643.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/68723iE83E94E25BD08DCE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ressel_0-1727703983643.png" alt="Ressel_0-1727703983643.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Store your table in a variable and use that variable in your script. In the screenshot example, that'd be 'dt'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Sep 2024 13:48:46 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Declaring-a-variable-inside-a-column-formula/m-p/802726#M97935</guid>
      <dc:creator>Ressel</dc:creator>
      <dc:date>2024-09-30T13:48:46Z</dc:date>
    </item>
    <item>
      <title>Re: Declaring a variable inside a column formula</title>
      <link>https://community.jmp.com/t5/Discussions/Declaring-a-variable-inside-a-column-formula/m-p/802740#M97937</link>
      <description>&lt;P&gt;Indeed a wonderful lecture on JSL scripting!&lt;/P&gt;&lt;P&gt;This 1hr will save you months of headache : )&lt;BR /&gt;&lt;BR /&gt;For you problem, please have a look at &lt;FONT face="courier new,courier"&gt;Col Min( ...)&lt;/FONT&gt;.&lt;BR /&gt;It will do all the job for you:&lt;BR /&gt;No need to &lt;EM&gt;declare&lt;/EM&gt; any rownum - no need to access the &lt;STRONG&gt;&lt;EM&gt;current data table&lt;/EM&gt;&lt;/STRONG&gt; nor to &lt;STRONG&gt;&lt;EM&gt;get rows where()&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;: )&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hogi_0-1727707451592.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/68727i2F216F9A5F2E853B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="hogi_0-1727707451592.png" alt="hogi_0-1727707451592.png" /&gt;&lt;/span&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" );
dt &amp;lt;&amp;lt; New Column( "Measurement type",
	Character,
	Formula(
		Map Value(
			:sex,
			{"F", "STUDY_VARIABLE", "M", "STUDY_CONTROL"}
		)
	)
);
:weight &amp;lt;&amp;lt; Set Name( "Control means" );
:age &amp;lt;&amp;lt; Set Name( "Control_Group" );


// ^^^^^^^^prepare table

// vvvvvvvv how to use Col Min()

New Column( "myCol",
	Formula(
		If( :Measurement type == "STUDY_VARIABLE",
			Col Minimum(
				If( :Measurement type == "STUDY_CONTROL",
					:Control means,
					Empty()
				),
				:Control_Group
			),
			:Control means
		)
	)
)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 30 Sep 2024 14:48:04 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Declaring-a-variable-inside-a-column-formula/m-p/802740#M97937</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2024-09-30T14:48:04Z</dc:date>
    </item>
  </channel>
</rss>

