cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP will suspend normal business operations for our Winter Holiday beginning on Wednesday, Dec. 24, 2025, at 5:00 p.m. ET (2:00 p.m. ET for JMP Accounts Receivable).
    Regular business hours will resume at 9:00 a.m. EST on Friday, Jan. 2, 2026.
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.

Discussions

Solve problems, and share tips and tricks with other JMP users.
%3CLINGO-SUB%20id%3D%22lingo-sub-341729%22%20slang%3D%22en-US%22%20mode%3D%22UPDATE%22%3EJSL%EC%9D%98%20COALESCE%20%ED%95%A8%EC%88%98%EC%99%80%20%EA%B0%99%EC%8A%B5%EB%8B%88%EB%8B%A4.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-341729%22%20slang%3D%22en-US%22%20mode%3D%22UPDATE%22%3E%3CP%3ECOALESCE%20%ED%95%A8%EC%88%98%EC%B2%98%EB%9F%BC%20X%20%EC%97%B4%EC%9D%B4%20null%EC%9D%B8%20%EA%B2%BD%EC%9A%B0%20%EB%8C%80%EC%B2%B4%20%EA%B0%92(%EC%98%88%3A%20A)%EC%9D%84%20%EA%B0%80%EC%A7%88%20%EC%88%98%20%EC%9E%88%EB%8A%94%20%ED%95%A8%EC%88%98%EB%A5%BC%20%EC%B0%BE%EA%B3%A0%20%EC%9E%88%EC%97%88%EA%B3%A0%20%EB%B0%A9%EC%A0%95%EC%8B%9D%EC%9D%80%20%EB%8B%A4%EC%9D%8C%EA%B3%BC%20%EA%B0%99%EC%8A%B5%EB%8B%88%EB%8B%A4.%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ECOALESCE(%3AX%2C%20A)%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EX%EA%B0%80%20null%EC%9D%B4%20%EC%95%84%EB%8B%88%EB%A9%B4%20X%20%EA%B0%92%EC%9D%84%20%EB%B0%98%ED%99%98%ED%95%A9%EB%8B%88%EB%8B%A4.%3C%2FP%3E%0A%3CP%3EX%EA%B0%80%20null%EC%9D%B4%EB%A9%B4%20%EA%B0%92%20A%EB%A5%BC%20%EB%B0%98%ED%99%98%ED%95%A9%EB%8B%88%EB%8B%A4.%3C%2FP%3E%0A%3CP%3E%20%3C%2FP%3E%0A%3CP%3E%EC%95%BD%EA%B0%84%20%EB%B3%B5%EC%9E%A1%ED%95%9C%20%EB%B0%A9%EC%A0%95%EC%8B%9D%EC%9D%84%20%EC%82%AC%EC%9A%A9%ED%95%98%EB%A9%B4%20%EC%9D%B4%EB%9F%AC%ED%95%9C%20%EA%B2%B0%EA%B3%BC%EB%A5%BC%20%EC%96%BB%EC%9D%84%20%EC%88%98%20%EC%9E%88%EB%8B%A4%EB%8A%94%20%EA%B2%83%EC%9D%84%20%EC%9D%B4%ED%95%B4%ED%96%88%EC%A7%80%EB%A7%8C%20%EA%B8%B0%EB%B3%B8%EC%A0%81%EC%9C%BC%EB%A1%9C%20JSL%EC%97%90%EC%84%9C%20%EC%9C%A0%EC%82%AC%ED%95%9C%20%EA%B8%B0%EB%8A%A5%EC%9D%84%20%EA%B0%80%EC%A7%88%20%EC%88%98%20%EC%9E%88%EB%8A%94%EC%A7%80%20%EA%B6%81%EA%B8%88%ED%95%A9%EB%8B%88%EB%8B%A4.%3C%2FP%3E%0A%3CP%3E%20%3C%2FP%3E%0A%3CP%3E%EB%8B%B9%EC%8B%A0%EC%9D%98%20%EB%8F%84%EC%9B%80%EC%9D%84%20%EC%A3%BC%EC%85%94%EC%84%9C%20%EB%8C%80%EB%8B%A8%ED%9E%88%20%EA%B0%90%EC%82%AC%ED%95%A9%EB%8B%88%EB%8B%A4.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-341729%22%20slang%3D%22en-US%22%20mode%3D%22UPDATE%22%3E%3CLINGO-LABEL%3E%EC%86%8C%EB%B9%84%EC%9E%90%20%EB%B0%8F%20%EC%8B%9C%EC%9E%A5%20%EC%A1%B0%EC%82%AC%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3E%EA%B2%B0%EA%B3%BC%20%EA%B3%B5%EC%9C%A0%20%EB%B0%8F%20%EC%A0%84%EB%8B%AC%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-341771%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%20%3A%20JSL%EC%9D%98%20COALESCE%20%ED%95%A8%EC%88%98%EC%B2%98%EB%9F%BC%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-341771%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%EB%82%B4%EC%9E%A5%20%EC%97%86%EC%9D%8C%3CA%20href%3D%22https%3A%2F%2Fdocumentation.sas.com%2F%3FcdcId%3Dpgmsascdc%26amp%3BcdcVersion%3D9.4_3.5%26amp%3BdocsetId%3Dsqlproc%26amp%3BdocsetTarget%3Dp1gdr5t7sd3g3qn1d7fg23zuwzml.htm%26amp%3Blocale%3Den%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3E%20COALESCE%3C%2FA%3E%20JSL%EC%9D%98%20%EA%B8%B0%EB%8A%A5.%20%EA%B7%B8%EB%9F%AC%EB%82%98%20%EB%8B%A8%EC%9D%BC%20%EC%97%B4%EC%9D%98%20%EA%B2%BD%EC%9A%B0%20%EA%B3%B5%EC%8B%9D%EC%9D%80%20%EA%B7%B8%EB%A0%87%EA%B2%8C%20%EB%B3%B5%EC%9E%A1%ED%95%98%EC%A7%80%20%EC%95%8A%EC%8A%B5%EB%8B%88%EB%8B%A4.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Eif(%20!Is%20Missing(%20%3AX%20)%2C%0A%20%3AX%2C%20%2F%2F%3AX%20is%20missing%0A%20%22A%22%20%2F%2Felse%0A)%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%EB%AC%BC%EB%A1%A0%2C%20%EC%97%B4%EC%9D%B4%20%EB%A7%8E%EC%9D%84%EC%88%98%EB%A1%9D%20%EB%8D%94%20%EA%B8%B8%EC%96%B4%20%EC%A7%80%EC%A7%80%EB%A7%8C%20%EC%97%AC%EC%A0%84%ED%9E%88%20%EB%82%98%EC%81%98%EC%A7%80%EB%8A%94%20%EC%95%8A%EC%8A%B5%EB%8B%88%EB%8B%A4.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Eif(%0A%20!Is%20Missing(%20%3AX%20)%2C%20%3AX%2C%20%2F%2F%3AX%20is%20not%20missing%0A%20!Is%20Missing(%20%3AY%20)%2C%20%3AY%2C%20%2F%2F%3AY%20is%20not%20missing%0A%20!Is%20Missing(%20%3AZ%20)%2C%20%3AZ%2C%20%2F%2F%3AZ%20is%20not%20missing%0A%20%22A%22%20%2F%2Felse%0A)%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fwww.jmp.com%2Fsupport%2Fhelp%2Fen%2F15.2%2F%23page%2Fjmp%2Fcomparison-functions-2.shtml%23ww2502397%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3E%EB%88%84%EB%9D%BD()%3C%2FA%3E%20%EB%AA%A9%EB%A1%9D%20%EB%98%90%EB%8A%94%20%ED%96%89%EB%A0%AC%20%EC%9D%B8%EC%88%98%EB%A5%BC%20%EC%B7%A8%ED%95%98%EA%B3%A0%20%ED%95%B4%EB%8B%B9%20%EC%9C%84%EC%B9%98%EC%97%90%20%EB%88%84%EB%9D%BD%EB%90%98%EC%97%88%EB%8A%94%EC%A7%80%20%EC%97%AC%EB%B6%80%EB%A5%BC%20%EB%82%98%ED%83%80%EB%82%B4%EB%8A%94%200%EA%B3%BC%201%EC%9D%98%20%EB%AA%A9%EB%A1%9D%20%EB%98%90%EB%8A%94%20%ED%96%89%EB%A0%AC%EC%9D%84%20%EB%B0%98%ED%99%98%ED%95%A9%EB%8B%88%EB%8B%A4.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3EIs%20Missing(%20%7B%22a%22%2C%20%22%20%22%2C%20%22c%22%7D%20)%3B%20%2F%2F%20returns%20%7B0%2C%201%2C%200%7D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%EC%95%84%EB%A7%88%EB%8F%84%20%EB%82%B4%EA%B0%80%20%EA%B7%B8%EA%B2%83%EC%9D%84%20%EC%82%AC%EC%9A%A9%ED%95%98%EC%97%AC%20%EB%8D%94%20%EA%B0%84%EB%8B%A8%ED%95%9C%20%EB%B2%84%EC%A0%84%EC%9D%84%20%EB%A7%8C%EB%93%A4%20%EC%88%98%EC%9E%88%EB%8A%94%20%EA%B2%83%EB%B3%B4%EB%8B%A4%20%EB%8D%94%20%EC%98%81%EB%A6%AC%ED%95%9C%20%EC%82%AC%EB%9E%8C%20%EC%9D%BC%20%EA%B2%83%EC%9E%85%EB%8B%88%EB%8B%A4.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%EB%AC%BC%EB%A1%A0%20%EC%84%A0%ED%83%9D%ED%95%9C%20%EB%B0%A9%EB%B2%95%EC%9D%84%20%EC%82%AC%EC%9A%A9%ED%95%98%EC%97%AC%3CA%20href%3D%22https%3A%2F%2Fwww.jmp.com%2Fsupport%2Fhelp%2Fen%2F15.2%2F%23page%2Fjmp%2Fcreate-custom-functions-transforms-and-formats.shtml%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3E%20%EB%A7%9E%EC%B6%A4%20%EA%B8%B0%EB%8A%A5%3C%2FA%3E%20%2C%20Coalesce%20().%3C%2FP%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
WakuWakuGoku
Level III

Like COALESCE function in JSL

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:

COALESCE(:X, A)

if X is not null, then it return the value of X

if X is null, then it return the value A

 

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.

 

Thank you very much for your help.

1 ACCEPTED SOLUTION

Accepted Solutions
Jeff_Perkinson
Community Manager Community Manager

Re: Like COALESCE function in JSL

There is no built-in COALESCE function in JSL. However, for a single column, the formula is not that complicated:

 

if( !Is Missing( :X ),
	:X, //:X is not missing
	"A" //else
);

 

Admittedly, it does get a bit more lengthy with more columns, but it's still not too bad.

 

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
);

 

Is Missing() will take a list or matrix argument and return a list or matrix of 0s and 1s indicating missing or not in those locations.

 

Is Missing( {"a", " ", "c"} ); // returns {0, 1, 0}

Perhaps someone more clever than I can use that to make a simpler version.

 

And, of course, whatever method you choose can be used to create a custom function, Coalesce().

-Jeff

View solution in original post

2 REPLIES 2
Jeff_Perkinson
Community Manager Community Manager

Re: Like COALESCE function in JSL

There is no built-in COALESCE function in JSL. However, for a single column, the formula is not that complicated:

 

if( !Is Missing( :X ),
	:X, //:X is not missing
	"A" //else
);

 

Admittedly, it does get a bit more lengthy with more columns, but it's still not too bad.

 

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
);

 

Is Missing() will take a list or matrix argument and return a list or matrix of 0s and 1s indicating missing or not in those locations.

 

Is Missing( {"a", " ", "c"} ); // returns {0, 1, 0}

Perhaps someone more clever than I can use that to make a simpler version.

 

And, of course, whatever method you choose can be used to create a custom function, Coalesce().

-Jeff
vince_faller
Super User (Alumni)

Re: Like COALESCE function in JSL

You could use loc nonmissing to just find the first one, it works for missing values as well as blank chars. 

 

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,
	<<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", 
	<<Formula(coalesce({:age, :sex, :height})) // row 2 should just be blank
);
Vince Faller - Predictum

Recommended Articles