cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
%3CLINGO-SUB%20id%3D%22lingo-sub-781042%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EHow%20do%20I%20count%20number%20of%20non-blank%20rows%20across%20specific%20rows%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-781042%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EI%20have%20the%20table%20displayed%20here%20and%20would%20like%20to%20make%20a%20new%20column%20that%20contains%20%22N%22%20which%20is%20the%20number%20of%20columns%20that%20have%20numbers%20but%20only%20for%20the%20columns%20labelled%20%22DecodeCount_BW**%22.%20For%20example%20for%20the%20first%20row%2C%20it%20should%20return%20%225%22%2C%20for%20the%20second%20row%20it%20should%20return%20%222%22%2C%20etc%3C%2FP%3E%3CP%3EIn%20Excel%20I%20do%20this%20with%20%22counta%22%2C%20but%20trying%20to%20learn%20JMP%20for%20improved%20statistical%20analysis%2C%20but%20I've%20getting%20stuck%20at%20simple%20things%20like%20this%20maybe%20due%20to%20my%20excel-formatted%20brain...%20Sorry%20if%20this%20is%20super%20basic%20but%20I%20can't%20find%20a%20formula%20on%20the%20list%20of%20formulas%20that%20does%20this..%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3CP%3EJMP17%20user%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-781042%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CLINGO-LABEL%3EContent%20Organization%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EData%20Blending%20and%20Cleanup%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-781079%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20How%20do%20I%20count%20number%20of%20non-blank%20rows%20across%20specific%20rows%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-781079%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EFormulas%20generally%20do%20not%20work%20in%20this%20direction%20that%20easily%20(calculating%20something%20by%20row%20instead%20of%20column).%20Depending%20what%20you%20are%20doing%20stacking%20your%20data%20first%20might%20be%20beneficial.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20can%20use%20formula%20for%20that%20(it%20might%20be%20a%20bit%20finicky)%2C%20but%20generally%20I%20would%20use%20scripting.%20Below%20is%20one%20example%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22jthi_0-1723483606619.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22jthi_0-1723483606619.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22jthi_0-1723483606619.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F67065iC98BBC30F59E15BC%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22jthi_0-1723483606619.png%22%20alt%3D%22jthi_0-1723483606619.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20Default%20To%20Here(1)%3B%0A%0Adt%20%3D%20New%20Table(%22Untitled%203%22%2C%0A%09Add%20Rows(3)%2C%0A%09Compress%20File%20When%20Saved(1)%2C%0A%09New%20Column(%22Column%201%22%2C%20Numeric%2C%20%22Continuous%22%2C%20Format(%22Best%22%2C%2012)%2C%20Set%20Values(%5B.%2C%20.%2C%20.%5D))%2C%0A%09New%20Column(%22Column%202%22%2C%20Numeric%2C%20%22Continuous%22%2C%20Format(%22Best%22%2C%2012)%2C%20Set%20Values(%5B.%2C%20.%2C%20.%5D))%2C%0A%09New%20Column(%22AB1%22%2C%20Numeric%2C%20%22Continuous%22%2C%20Format(%22Best%22%2C%2012)%2C%20Set%20Values(%5B2%2C%20.%2C%20.%5D))%2C%0A%09New%20Column(%22AB2%22%2C%20Numeric%2C%20%22Continuous%22%2C%20Format(%22Best%22%2C%2012)%2C%20Set%20Values(%5B.%2C%202%2C%201%5D))%2C%0A%09New%20Column(%22AB3%22%2C%20Numeric%2C%20%22Continuous%22%2C%20Format(%22Best%22%2C%2012)%2C%20Set%20Values(%5B.%2C%205%2C%20.%5D))%0A)%3B%0A%0Adt%20%26lt%3B%26lt%3B%20New%20Column(%22N%22%2C%20Numeric%2C%20Continuous)%3B%0A%0Acols_of_interest%20%3D%20Filter%20Each(%7Bcolname%7D%2C%20dt%20%26lt%3B%26lt%3B%20Get%20Column%20Names(%22String%22)%2C%0A%09Starts%20With(colname%2C%20%22AB%22)%3B%0A)%3B%0A%0AFor%20Each%20Row(Current%20Data%20Table()%2C%0A%09%3AN%20%3D%20Sum(!Is%20Missing(dt%5BRow()%2C%20cols_of_interest%5D))%3B%0A)%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3Eand%20if%20you%20really%20want%20to%20use%20formula%20you%20might%20be%20able%20to%20use%20something%20like%20this%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3EAs%20Constant(cols_of_interest%20%3D%20Filter%20Each(%7Bcolname%7D%2C%20Current%20Data%20Table()%20%26lt%3B%26lt%3B%20Get%20Column%20Names(%22String%22)%2C%0A%09Starts%20With(colname%2C%20%22AB%22)%3B%0A))%3B%0ASum(!Is%20Missing(dt%5BRow()%2C%20cols_of_interest%5D))%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EYou%20have%20to%20figure%20your%20own%20comparison%20to%20filter%20down%20to%20columns%20of%20interest%20(Starts%20With%20should%20work%20for%20your%20data%20also)%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-781081%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20How%20do%20I%20count%20number%20of%20non-blank%20rows%20across%20specific%20rows%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-781081%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3ETables%2FSummary%20can%20count%20for%20you.%20To%20make%20it%20count%20over%20multiple%20columns%2C%20you%20have%20to%20fist%20stack%20the%20data%3A%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Edt%20%3D%20New%20Table(%20%22test%22%2C%0A%09Add%20Rows(%206%20)%2C%0A%09New%20Column(%20%22W8%22%2CSet%20Values(%20%5B2%2C%205%2C%20.%2C%205%2C%20.%2C%206%5D%20))%2C%0A%09New%20Column(%20%22W9%22%2CSet%20Values(%20%5B2%2C%20.%2C%203%2C%203%2C%201%2C%202%5D%20))%2C%0A%09New%20Column(%20%22W1%22%2CSet%20Values(%20%5B2%2C%20.%2C%20.%2C%20.%2C%20.%2C%20.%5D%20))%2C%0A%09New%20Column(%20%22W2%22%2CSet%20Values(%20%5B3%2C%20.%2C%20.%2C%20.%2C%20.%2C%20.%5D%20))%2C%0A%09New%20Column(%20%22W3%22%2CSet%20Values(%20%5B3%2C%20.%2C%20.%2C%20.%2C%20.%2C%20.%5D%20))%2C%0A%09New%20Column(%20%22W4%22%2CSet%20Values(%20%5B.%2C%20.%2C%204%2C%20.%2C%202%2C%20.%5D%20))%2C%0A%09New%20Column(%20%22W5%22%2CSet%20Values(%20%5B.%2C%202%2C%20.%2C%20.%2C%20.%2C%20.%5D%20))%2C%0A%09New%20Column(%20%22W6%22%2CSet%20Values(%20%5B.%2C%20.%2C%205%2C%20.%2C%203%2C%20.%5D%20)))%3B%0A%0Adt%20%26lt%3B%26lt%3B%20New%20Column(%20%22row%22%2CFormula(%20Row()%20))%3B%0Adtstack%20%3Ddt%20%26lt%3B%26lt%3B%20Stack(%09columns(%20%3AW8%2C%20%3AW9%2C%20%3AW1%2C%20%3AW2%2C%20%3AW3%2C%20%3AW4%2C%20%3AW5%2C%20%3AW6%20)%2C%22Non-stacked%20columns%22n(%20Keep(%20%3Arow%20)%20))%3B%0Adtstack%20%26lt%3B%26lt%3B%20Summary(%09Group(%20%3Arow%20)%2C%09N(%20%3AData%20)%09)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ebtw%3A%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3E%22Non-stacked%20columns%22n%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3Ea%20named%20argument%20which%20needs%20to%20be%20written%20as%26nbsp%3B%20%3CFONT%20face%3D%22courier%20new%2Ccourier%22%3E%22...%22n%3C%2FFONT%3E.%20Argh!%3C%2FP%3E%3CP%3EHow%20good%20that%20enhanced%20log%20knows%20these%20details%20...%3C%2FP%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar

How do I count number of non-blank rows across specific rows?

I have the table displayed here and would like to make a new column that contains "N" which is the number of columns that have numbers but only for the columns labelled "DecodeCount_BW**". For example for the first row, it should return "5", for the second row it should return "2", etc

In Excel I do this with "counta", but trying to learn JMP for improved statistical analysis, but I've getting stuck at simple things like this maybe due to my excel-formatted brain... Sorry if this is super basic but I can't find a formula on the list of formulas that does this..

Thanks

JMP17 user

2 REPLIES 2
jthi
Super User

Re: How do I count number of non-blank rows across specific rows?

Formulas generally do not work in this direction that easily (calculating something by row instead of column). Depending what you are doing stacking your data first might be beneficial.

 

You can use formula for that (it might be a bit finicky), but generally I would use scripting. Below is one example

jthi_0-1723483606619.png

 

Names Default To Here(1);

dt = New Table("Untitled 3",
	Add Rows(3),
	Compress File When Saved(1),
	New Column("Column 1", Numeric, "Continuous", Format("Best", 12), Set Values([., ., .])),
	New Column("Column 2", Numeric, "Continuous", Format("Best", 12), Set Values([., ., .])),
	New Column("AB1", Numeric, "Continuous", Format("Best", 12), Set Values([2, ., .])),
	New Column("AB2", Numeric, "Continuous", Format("Best", 12), Set Values([., 2, 1])),
	New Column("AB3", Numeric, "Continuous", Format("Best", 12), Set Values([., 5, .]))
);

dt << New Column("N", Numeric, Continuous);

cols_of_interest = Filter Each({colname}, dt << Get Column Names("String"),
	Starts With(colname, "AB");
);

For Each Row(Current Data Table(),
	:N = Sum(!Is Missing(dt[Row(), cols_of_interest]));
);

and if you really want to use formula you might be able to use something like this

As Constant(cols_of_interest = Filter Each({colname}, Current Data Table() << Get Column Names("String"),
	Starts With(colname, "AB");
));
Sum(!Is Missing(dt[Row(), cols_of_interest]));

You have to figure your own comparison to filter down to columns of interest (Starts With should work for your data also)

-Jarmo
hogi
Level XII

Re: How do I count number of non-blank rows across specific rows?

Tables/Summary can count for you. To make it count over multiple columns, you have to fist stack the data:

dt = New Table( "test",
	Add Rows( 6 ),
	New Column( "W8",Set Values( [2, 5, ., 5, ., 6] )),
	New Column( "W9",Set Values( [2, ., 3, 3, 1, 2] )),
	New Column( "W1",Set Values( [2, ., ., ., ., .] )),
	New Column( "W2",Set Values( [3, ., ., ., ., .] )),
	New Column( "W3",Set Values( [3, ., ., ., ., .] )),
	New Column( "W4",Set Values( [., ., 4, ., 2, .] )),
	New Column( "W5",Set Values( [., 2, ., ., ., .] )),
	New Column( "W6",Set Values( [., ., 5, ., 3, .] )));

dt << New Column( "row",Formula( Row() ));
dtstack =dt << Stack(	columns( :W8, :W9, :W1, :W2, :W3, :W4, :W5, :W6 ),"Non-stacked columns"n( Keep( :row ) ));
dtstack << Summary(	Group( :row ),	N( :Data )	);

 

btw:

"Non-stacked columns"n

a named argument which needs to be written as  "..."n. Argh!

How good that enhanced log knows these details ...