cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP Security Notice: CVE-2026-109618 and CVE-2026-109619

    JMP promptly initiated a review of its products, services, and relevant infrastructure for exposure to CVE-2026-109618 and CVE-2026-109619.

    Our assessment of JMP products has not identified exposure to these vulnerabilities. Where remediation was required within supporting environments, appropriate security updates and controls have been applied and validated.

    We have identified no evidence of successful exploitation or unauthorized access to JMP systems or customer information associated with these vulnerabilities.

    JMP continues to monitor the issue and relevant vendor guidance. No action is required by JMP customers at this time.

  • Don’t miss your chance to experience Discovery Summit Europe at our best available rate! Early bird registration through 31 Oct.
  • Graph Builder Toolbar streamlines interactive graphing. Creates shortcuts on Report and GraphBuilder Helpers toolbars. Download and install the extension.

Discussions

Solve problems, and share tips and tricks with other JMP users.
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