<?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 Like COALESCE function in JSL in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Like-COALESCE-function-in-JSL/m-p/341729#M59071</link>
    <description>&lt;P&gt;I have been looking for the function with which we could have an alternative value(e.g. A) if the column X is null, like COALESCE function, and the equation could be something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;COALESCE(:X, A)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;if X is not null, then it return the value of X&lt;/P&gt;
&lt;P&gt;if X is null, then it return the value A&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I understood that we manage to have such results by having a bit complicated equation, but I was wondering if we could have similar function in JSL by default.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you very much for your help.&lt;/P&gt;</description>
    <pubDate>Sat, 10 Jun 2023 20:41:48 GMT</pubDate>
    <dc:creator>WakuWakuGoku</dc:creator>
    <dc:date>2023-06-10T20:41:48Z</dc:date>
    <item>
      <title>Like COALESCE function in JSL</title>
      <link>https://community.jmp.com/t5/Discussions/Like-COALESCE-function-in-JSL/m-p/341729#M59071</link>
      <description>&lt;P&gt;I have been looking for the function with which we could have an alternative value(e.g. A) if the column X is null, like COALESCE function, and the equation could be something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;COALESCE(:X, A)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;if X is not null, then it return the value of X&lt;/P&gt;
&lt;P&gt;if X is null, then it return the value A&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I understood that we manage to have such results by having a bit complicated equation, but I was wondering if we could have similar function in JSL by default.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you very much for your help.&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 20:41:48 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Like-COALESCE-function-in-JSL/m-p/341729#M59071</guid>
      <dc:creator>WakuWakuGoku</dc:creator>
      <dc:date>2023-06-10T20:41:48Z</dc:date>
    </item>
    <item>
      <title>Re: Like COALESCE function in JSL</title>
      <link>https://community.jmp.com/t5/Discussions/Like-COALESCE-function-in-JSL/m-p/341771#M59076</link>
      <description>&lt;P&gt;There is no built-in &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=sqlproc&amp;amp;docsetTarget=p1gdr5t7sd3g3qn1d7fg23zuwzml.htm&amp;amp;locale=en" target="_self"&gt;COALESCE&lt;/A&gt; function in JSL. However, for a single column, the formula is not that complicated:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;if( !Is Missing( :X ),
	:X, //:X is not missing
	"A" //else
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Admittedly, it does get a bit more lengthy with more columns, but it's still not too bad.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;if(
	!Is Missing( :X ), :X, //:X is not missing
	!Is Missing( :Y ), :Y, //:Y is not missing
	!Is Missing( :Z ), :Z, //:Z is not missing
	"A" //else
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.jmp.com/support/help/en/15.2/#page/jmp/comparison-functions-2.shtml#ww2502397" target="_self"&gt;Is Missing()&lt;/A&gt; will take a list or matrix argument and return a list or matrix of 0s and 1s indicating missing or not in those locations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Is Missing( {"a", " ", "c"} ); // returns {0, 1, 0}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Perhaps someone more clever than I can use that to make a simpler version.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And, of course, whatever method you choose can be used to create a &lt;A href="https://www.jmp.com/support/help/en/15.2/#page/jmp/create-custom-functions-transforms-and-formats.shtml" target="_self"&gt;custom function&lt;/A&gt;, Coalesce().&lt;/P&gt;</description>
      <pubDate>Tue, 15 Dec 2020 12:01:00 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Like-COALESCE-function-in-JSL/m-p/341771#M59076</guid>
      <dc:creator>Jeff_Perkinson</dc:creator>
      <dc:date>2020-12-15T12:01:00Z</dc:date>
    </item>
    <item>
      <title>Re: Like COALESCE function in JSL</title>
      <link>https://community.jmp.com/t5/Discussions/Like-COALESCE-function-in-JSL/m-p/341788#M59078</link>
      <description>&lt;P&gt;You could use loc nonmissing to just find the first one, it works for missing values as well as blank chars.&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");
// blanking out some rows. 
dt:age[[2, 5, 8]] = .;
dt:sex[[2, 9, 18]] = "";
dt:height[[2, 4, 14]] = .;
dt:weight[[1, 4, 14]] = .;



coalesce = function({list_of_whatever}, 
	{DEFAULT LOCAL}, 
	l = Evallist(list_of_whatever);
	lnm = LocNonMissing(l);
	if(nitems(lnm), 
		return(char(l[lnm[1]])); // assuming you'll want to use both numeric and character columns
	);
);
// this should never be the weight value
New Column("Coalesce", character,
	&amp;lt;&amp;lt;Formula(coalesce({:age, :sex, :height, "will never get to weight", :weight}))
);
// if all values in the list are blank, it will just be ""
New Column("Coalesce all missing", 
	&amp;lt;&amp;lt;Formula(coalesce({:age, :sex, :height})) // row 2 should just be blank
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Dec 2020 01:01:13 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Like-COALESCE-function-in-JSL/m-p/341788#M59078</guid>
      <dc:creator>vince_faller</dc:creator>
      <dc:date>2020-12-15T01:01:13Z</dc:date>
    </item>
  </channel>
</rss>

