<?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: Best Way To Write A Formula With A Potentially Missing Column Reference in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Best-Way-To-Write-A-Formula-With-A-Potentially-Missing-Column/m-p/944117#M109606</link>
    <description>&lt;P&gt;I think my basic objection to the current method is that it looks bloated.&amp;nbsp; There are 2 iterations of the same code with and without the intermittent column.&amp;nbsp; I'd have thought there would have been something analogous to a Try() statement to deal with the inconsistency.&amp;nbsp; Something of that kind would also make the editing process easier.&lt;/P&gt;</description>
    <pubDate>Fri, 24 Apr 2026 13:40:53 GMT</pubDate>
    <dc:creator>SpannerHead</dc:creator>
    <dc:date>2026-04-24T13:40:53Z</dc:date>
    <item>
      <title>Best Way To Write A Formula With A Potentially Missing Column Reference</title>
      <link>https://community.jmp.com/t5/Discussions/Best-Way-To-Write-A-Formula-With-A-Potentially-Missing-Column/m-p/943935#M109597</link>
      <description>&lt;P&gt;I have a script that creates a formula based on the contents of an object.&amp;nbsp; In some instances, the entry that fills in the object is bypassed.&amp;nbsp; N Items(yVars) ==0 in that case.&amp;nbsp; How can I have the formula calculate without the column reference if empty?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The case below is overly complex where I check for the presence of an entry and use an If() statement to create alternative actions.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If( N Items( yVars ) == 0,
	Data Table( "HIRP" ) &amp;lt;&amp;lt; New Column( "Average PTC",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Formula(
			Col Mean(
				Col Maximum( :Power, :Heater, :HD_NUM ),
				:Heater,
				:WAFER_SUBSTRATE_LOT_ID_IDX
			)
		)
	),
	Eval(
		Eval Expr(
			Data Table( "HIRP" ) &amp;lt;&amp;lt; New Column( "Average PTC",
				Numeric,
				"Continuous",
				Format( "Best", 12 ),
				Formula(
					Col Mean(
						Col Maximum( :Power, :Heater, :HD_NUM ),
						:Heater,
						Expr(
							Name Expr( As Column( Divider ) )
						)
					)
				)
			)
		)
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Apr 2026 20:41:24 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Best-Way-To-Write-A-Formula-With-A-Potentially-Missing-Column/m-p/943935#M109597</guid>
      <dc:creator>SpannerHead</dc:creator>
      <dc:date>2026-04-23T20:41:24Z</dc:date>
    </item>
    <item>
      <title>Re: Best Way To Write A Formula With A Potentially Missing Column Reference</title>
      <link>https://community.jmp.com/t5/Discussions/Best-Way-To-Write-A-Formula-With-A-Potentially-Missing-Column/m-p/943959#M109599</link>
      <description>&lt;P&gt;Here is one way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;//first a table to add columns to
Names default to here(1);
dt = New Table( "Test Table",
	Add Rows( 2 ),
	New Column( "a", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 2] ) )
);

//this one does create a column
if(!Contains(dt &amp;lt;&amp;lt; get column names("string"), "b"),
	dt &amp;lt;&amp;lt; New Column( "b", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [3, 4] ) )
);

//this does not since b already exists
if(!Contains(dt &amp;lt;&amp;lt; get column names("string"), "b"),
	dt &amp;lt;&amp;lt; New Column( "b", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [5, 6] ) )
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Apr 2026 22:30:37 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Best-Way-To-Write-A-Formula-With-A-Potentially-Missing-Column/m-p/943959#M109599</guid>
      <dc:creator>ih</dc:creator>
      <dc:date>2026-04-23T22:30:37Z</dc:date>
    </item>
    <item>
      <title>Re: Best Way To Write A Formula With A Potentially Missing Column Reference</title>
      <link>https://community.jmp.com/t5/Discussions/Best-Way-To-Write-A-Formula-With-A-Potentially-Missing-Column/m-p/943999#M109602</link>
      <description>&lt;P&gt;Is there a specific reason to avoid doing what you are currently? If column reference is empty, don't add it to the formula.&lt;/P&gt;
&lt;P&gt;There really isn't anything complex in your way of doing it and it is easy to read and understand.&amp;nbsp;You could use if-statement to just set the formula which will reduce the repetition slightly. I would use either this or the way you are doing it (if I understand your question correctly)&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); 
// myvar = 1;

dt = Open("$SAMPLE_DATA/Big Class.jmp");

newcol = dt &amp;lt;&amp;lt; New Column("Test", Numeric, Continuous);

If(Is Missing(myvar),
	newcol &amp;lt;&amp;lt; Set Formula(
		:height/:weight
	);
,
	newcol &amp;lt;&amp;lt; Set Formula(
		:weight/:height
	)	
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Some more difficult to read, understand and possibly debug options:&lt;/P&gt;
&lt;P&gt;You can build the formula expression in if statement and then set the formula&amp;nbsp;&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); 
myvar = 1;
dt = Open("$SAMPLE_DATA/Big Class.jmp");

fexpr = If(Is Missing(myvar), Name Expr(:height/:weight), Name Expr(:weight/:height));

Eval(EvalExpr(
	newcol = dt &amp;lt;&amp;lt; New Column("Test", Numeric, Continuous, Formula(
		Expr(NameExpr(fexpr))
	))
));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you can use the if statement inside your formula evaluation (unnecessary complicated in my opinion)&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;Names Default To Here(1); 

dt = Open("$SAMPLE_DATA/Big Class.jmp");

newcol = dt &amp;lt;&amp;lt; New Column("Test", Numeric, Continuous);

Eval(Substitute(
	Expr(newcol &amp;lt;&amp;lt; Set Formula(
		_fexpr_
	)),
	Expr(_fexpr_), 	If(Is Missing(myvar), Name Expr(:height/:weight), Name Expr(:weight/:height))
));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Apr 2026 04:16:07 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Best-Way-To-Write-A-Formula-With-A-Potentially-Missing-Column/m-p/943999#M109602</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2026-04-24T04:16:07Z</dc:date>
    </item>
    <item>
      <title>Re: Best Way To Write A Formula With A Potentially Missing Column Reference</title>
      <link>https://community.jmp.com/t5/Discussions/Best-Way-To-Write-A-Formula-With-A-Potentially-Missing-Column/m-p/944117#M109606</link>
      <description>&lt;P&gt;I think my basic objection to the current method is that it looks bloated.&amp;nbsp; There are 2 iterations of the same code with and without the intermittent column.&amp;nbsp; I'd have thought there would have been something analogous to a Try() statement to deal with the inconsistency.&amp;nbsp; Something of that kind would also make the editing process easier.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Apr 2026 13:40:53 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Best-Way-To-Write-A-Formula-With-A-Potentially-Missing-Column/m-p/944117#M109606</guid>
      <dc:creator>SpannerHead</dc:creator>
      <dc:date>2026-04-24T13:40:53Z</dc:date>
    </item>
    <item>
      <title>Re: Best Way To Write A Formula With A Potentially Missing Column Reference</title>
      <link>https://community.jmp.com/t5/Discussions/Best-Way-To-Write-A-Formula-With-A-Potentially-Missing-Column/m-p/944158#M109611</link>
      <description>&lt;P&gt;You cannot really deal with missing column reference inside the formula (you could use Try() but it will most likely make the formula very slow and I wouldn't do it).&amp;nbsp;I did provide some options to avoid the replication. You could also create a function to create the column/add the formula.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Apr 2026 16:12:47 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Best-Way-To-Write-A-Formula-With-A-Potentially-Missing-Column/m-p/944158#M109611</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2026-04-24T16:12:47Z</dc:date>
    </item>
  </channel>
</rss>

