BookmarkSubscribe
Choose Language Hide Translation Bar
mwyant
Community Trekker

Remove rows with one or more empty values using JSL

I have a table where each row contains a single measurement type at three temperatures, each stored in its own column. Ultimately, I want to calculate the deltas between these measurements and then stack that data into a new table. However, not all measurements are taken at all three temperatures, and I need to exclude those measurements (rows) where one or more of the data columns are empty. I need to do this using a JMP 9.0 script.

Given:

dtSplit =

MeasurementT1T2T3
Measurement A51289
Measurement B138
Measurement C5257
Measurement D2221
Measurement E8
Measurement F15
Measurement G54

I need to produce:

dtClean =

MeasurementT1T2T3
Measurement A51289

I was trying to use something like:

dtSplit << Select Where(
     Is Empty(:T1) ||
     Is Empty(:T2) ||
     is Empty(:T3)
) << Delete Rows;

However, any Select Where(Is Empty(:COL)) always selects all rows.

I'm sure I am missing something simple, your help is greatly appreciated, thanks,

- Matt

0 Kudos
1 ACCEPTED SOLUTION

Accepted Solutions
pmroz
Super User

Re: Remove rows with one or more empty values using JSL

You were using the string concatenation operator || instead of the OR operator |.  As MS showed you need to use the Is Missing function and not Is Empty.  Your code becomes:

 

dtsplit << Select Where(Is missing(:T1) | Is missing(:T2) | is missing(:T3)) << Delete Rows;
11 REPLIES 11
ms
Super User ms
Super User

Re: Remove rows with one or more empty values using JSL

This can be accomplished in different ways. For numeric columns matrix functions often are effective.

Here is an example deleting all rows with missing cells in columns 2, 3 & 4:

 

 

keeprows = Loc Nonmissing( dtSplit << get as matrix( {2, 3, 4} ) );
dtSplit << select rows( keeprows ) << invert Row Selection << delete rows;

 

 

Here is an alternative approach making a subset of the columns with no missing cells (keeping the original table unchanged):

 

dtClean = dtSplit << Clear Column Selection() << subset( rows( Loc Nonmissing( dt << get as matrix( {2, 3, 4} ) ) ) );
0 Kudos
ms
Super User ms
Super User

Re: Remove rows with one or more empty values using JSL

Sorry, I missed the JMP9 requirement. The function Loc Nonmissing() appears to be new to JMP 10 so the above do not work in JMP 9.

 

Heres an alternative approach that works in JMP 9, similar to your code but using a loop.

 

 

For( i = 2, i <= 4, i++,
  dtSplit << select where( Is Missing( Column( i )[] ) ) << delete rows
);

 

0 Kudos
pmroz
Super User

Re: Remove rows with one or more empty values using JSL

You were using the string concatenation operator || instead of the OR operator |.  As MS showed you need to use the Is Missing function and not Is Empty.  Your code becomes:

 

dtsplit << Select Where(Is missing(:T1) | Is missing(:T2) | is missing(:T3)) << Delete Rows;
mwyant
Community Trekker

Re: Remove rows with one or more empty values using JSL

Using the concatenation operator was a transcription error--old habits die hard.

turns out the problem was my column names, which were actually '88', '95' and '105', and using Is Missing(:88) selected all rows.


dtsplit << Select Where(Is missing(:Name("T1")) | Is missing(:Name("T2")) | is missing(:Name("T3"))) << Delete Rows;


Works great.

0 Kudos
Vball247
Community Trekker

Re: Remove rows with one or more empty values using JSL

Great discussion. We had similar issue, where importing from sensor files we had a lot of empty rows at the end of the file. We wanted to remove rows where no sensor data was located. However, did not want to remove rows where there still was some information. Below was written in JMP14, but think it will work for previous versions. In JMP14, I know there is Row Selection > Select Duplicate Rows. But could not find a similar function that would sum all the numeric columns across one row. In the script below, Sum() would return null across the row in the matrix, but I wanted a zero. Found the output of V Sum() would return 0 for all null. To make work, just had to transpose the row vector into a column vector. This works for no matter how many numeric columns you have, as long as they are all empty. Still interested if someone has a better solution.

 

dt = Current Data Table();

// Get all numeric data

m = dt << Get As Matrix;

// for each row, test if the V Sum is 0 or non-zero
// V Sum returns 0 for all null
// Sum() returns null for all null

rowlist = {};

For(i= N Rows(m), i>=1,i--,
	If(V Sum(Transpose(m[i,0]))[1] == 0,
		Insert Into(rowlist,i)
	)
);
dt << Delete Rows(rowlist);
0 Kudos
Highlighted
ENTHU
Community Trekker

Re: Remove rows with one or more empty values using JSL

Hi,

I am trying to do slightly the same.

I need to check if a cell is empty and then delete the row if yes.

I tried the following -

dt << select where( Is Missing( Column( dt,"Value" )[7] ) ) << delete rows;

But it deletes all rows in the table.

Looking for ideas.

0 Kudos
txnelson
Super User

Re: Remove rows with one or more empty values using JSL

Your code is only checking for Row 7.  You need to test each row

dt << select where( Is Missing( Column( dt,"weight" )[row()] ) ) << delete rows;
Jim
0 Kudos
pmroz
Super User

Re: Remove rows with one or more empty values using JSL

If you're only checking a single cell:

if ( Is Missing( Column( dt,"Value" )[7] ),
	dt << delete rows([7]);
);
0 Kudos
new_2_JMP
New Contributor

Re: Remove rows with one or more empty values using JSL

HI

This is my first post and not sure if the attached Excel file goes through or not. If not, 

I am also attaching the PNG of the sample data fileData_table_example.PNG 
I am very new to JMP (I am using JMP 14) and need helps with the row delete script.
My data table contains data of many different devices where each device is test for
four different failures (sensitivity, mask, EVM and power) across a wide frequency ranges
from 10 MHz to 1000 Mhz. Passing devices are the ones that have empty cells "" for all four
test across frequency ranges and I would like to remove them from the data table.
(delete the rows in green of the attached Excel file - devices C, G, H, I, J, K, and N)


1st Problem: How to delete empty rows (with columns 10 MHz to 1000 MHz = empty)
Below command I found is similar but not useful because I have 100 different columns and "and"
them all out is quite lengthy and not scalable if we later decided to increase the frequency
beyound 1000 MHz

dtsplit << Select Where(Is missing(:T1) | Is missing(:T2) | is missing(:T3)) << Delete Rows;

I also tried this command:
For( i = 2, i <= 101, i++,
dtSplit << select where( Is Missing( Column( i )[] ) ) << delete rows
);
This command gives me an error:
In the following script, error marked by /*###*/
dt = Current Data Table();
For( i = 2, i <= 100, i++,
dtSplit/*###*/ <<select where( Is Missing( Column( i )[] ) ) << delete rows
);

2nd Problem: Deleted rows must in the multiple of 4 since each device is being tested 4 times.
I am not exactly sure how to do that

would really appreciate your helps on this

 

Thanks
new_2_JMP

 

 

0 Kudos