cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
danielrbiber
Level III

Else Statement not returning in column formula

I'm creating a new column with some regex statements.  I have the tough regex bit figured out but the else statement returns <no data>?  Any ideas as to why this is?  I have several other if containing column formula of the same syntax that return the else statements.

 

The formula should return the integer directly before " ct" or "ct" or should return "bulk".

For example:

:Packaging          :Packaging_Ct

abso 400ct           400

ebso 100 ct          100

fiber                      bulk

 

Data Table("MetaDataGelSplit") << New Column(
	"Packaging_Ct",
	Character,
	Nominal,
	formula(
		If(
			Num( Regex( :Packaging, "\d+(?=\s+ct)" ) ) > 0, Regex( :Packaging, "\d+(?=\s+ct)" ),
			Num( Regex( :Packaging, "\d+(?=ct)" ) ) > 0, Regex( :Packaging, "\d+(?=ct)" ),
			"bulk"
		)
	)
);

Thanks in advance for the help.

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Else Statment not returning in column formula

If a numeric value is not found in the Regex it does not return a zero, it returns a missing value, by changing the comparisons to using IsMissing() the logic works correctly

current data table() << New Column(
	"Packaging_Ct",
	Character,
	Nominal,
	formula(
		If(
			isMissing(Num( Regex( :Packaging, "\d+(?=\s+ct)" ) )) ==0, Regex( :Packaging, "\d+(?=\s+ct)" ),
			isMissing(Num( Regex( :Packaging, "\d+(?=ct)" ) )) == 0, Regex( :Packaging, "\d+(?=ct)" ),
			"bulk";
		);
	)
);
Jim

View solution in original post

3 REPLIES 3
txnelson
Super User

Re: Else Statment not returning in column formula

If a numeric value is not found in the Regex it does not return a zero, it returns a missing value, by changing the comparisons to using IsMissing() the logic works correctly

current data table() << New Column(
	"Packaging_Ct",
	Character,
	Nominal,
	formula(
		If(
			isMissing(Num( Regex( :Packaging, "\d+(?=\s+ct)" ) )) ==0, Regex( :Packaging, "\d+(?=\s+ct)" ),
			isMissing(Num( Regex( :Packaging, "\d+(?=ct)" ) )) == 0, Regex( :Packaging, "\d+(?=ct)" ),
			"bulk";
		);
	)
);
Jim

Re: Else Statmente not returning in column formula

In addition to @txnelson's advice, I try to build up the formula by starting with the basic Regex() function. That is, before applying Num(), make sure that you are getting what you need from Regex() first. Don't add unnecessary layers to the formula until you are satisfied that the lowest level is working for you.

 

Also, Regex() is relatively 'expensive,' so I would save the result from the first call in a variable and re-use it instead of call Regex() again with the same expression. it might make a big difference in large data tables.

vince_faller
Super User (Alumni)

Re: Else Statmente not returning in column formula

Seems like you could cut out one of the regex entirely as well. 

 

n = Regex( :Packaging, "(\d+)(?=\s*ct)", "\1");
if(ismissing(num(n)), 
	"bulk", 
	num(n)
)
Vince Faller - Predictum