BookmarkSubscribe
Choose Language Hide Translation Bar
Community Trekker

## Is there any way to quickly get the number of negative values in a column?

Hello, everyone!

I need to count the number or percentage of negative Numbers on the "Arrival Delay" column.

This functionality does not appear to be found in the JMP's menu operations and formulas.
There is a =countif(,"<0") in excel that can do quickly.
JMP wants to use a loop?

dt = Open( "\$SAMPLE_DATA/Airline Delays.jmp" );

2 ACCEPTED SOLUTIONS

Accepted Solutions
Super User

## Re: Is there any way to quickly get the number of negative values in a column?

Use a Transformation variable with a specified formula of

If(:Arrival Delay < 0, 1, 0)

Then use Sum as the statistic in the Summary Platform

Jim
Staff (Retired)

## Re: Is there any way to quickly get the number of negative values in a column?

Jim's answer is great; here are two more that avoid creating a column but have different side effects:

``````dt = Open( "\$sample_data/big class.jmp" );

// using table subscripts, suitable for  use in a column formula.
// As Constant calculates the result once, not for every row.
As Constant( N Rows( Loc( dt[0, "age"] < 15 ) ) ); // 27

// using row selection, suitable for JSL programs. Avoids a temporary
// matrix but does change the selection state of the table.
dt << selectwhere( age < 15 );
N Rows( dt << getselectedrows ); // 27
``````

What you choose depends a bit on whether you'll use it in a column formula or in a JSL program; JMP added the As Constant function (mostly) to support column formulas that need to make an expensive calculation. Without it, JMP would count the number of rows for every row, leading to N^2 performance issues.

Explaining the first example: dt[0,"age"] returns a matrix from the table (post). 0 means all rows. Comparing that matrix with < 15 returns a matrix of 0 and 1 results. Loc([ 1 0 1 0]) returns a smaller matrix of the locations of the non zero (true) results. NRows or NItems reports the number of elements. As Constant isn't needed in a JSL program if you capture the answer in a variable.

Craige
5 REPLIES 5
Super User

## Re: Is there any way to quickly get the number of negative values in a column?

Use a Transformation variable with a specified formula of

If(:Arrival Delay < 0, 1, 0)

Then use Sum as the statistic in the Summary Platform

Jim
Community Trekker

## Re: Is there any way to quickly get the number of negative values in a column?

Thank Jim!
That seems to be the only way.
Staff (Retired)

## Re: Is there any way to quickly get the number of negative values in a column?

Jim's answer is great; here are two more that avoid creating a column but have different side effects:

``````dt = Open( "\$sample_data/big class.jmp" );

// using table subscripts, suitable for  use in a column formula.
// As Constant calculates the result once, not for every row.
As Constant( N Rows( Loc( dt[0, "age"] < 15 ) ) ); // 27

// using row selection, suitable for JSL programs. Avoids a temporary
// matrix but does change the selection state of the table.
dt << selectwhere( age < 15 );
N Rows( dt << getselectedrows ); // 27
``````

What you choose depends a bit on whether you'll use it in a column formula or in a JSL program; JMP added the As Constant function (mostly) to support column formulas that need to make an expensive calculation. Without it, JMP would count the number of rows for every row, leading to N^2 performance issues.

Explaining the first example: dt[0,"age"] returns a matrix from the table (post). 0 means all rows. Comparing that matrix with < 15 returns a matrix of 0 and 1 results. Loc([ 1 0 1 0]) returns a smaller matrix of the locations of the non zero (true) results. NRows or NItems reports the number of elements. As Constant isn't needed in a JSL program if you capture the answer in a variable.

Craige
Community Trekker

I use it in JSL.