cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Instantly extract effect sizes, F-ratios, and FDR-adjusted p-values from your models with the Calculate Effects Sizes extension, available now in the JMP Marketplace!
  • New to JMP? Join us Sept. 23-24 for the Early User Edition of Discovery Summit, tailor-made for new users. Register now for free!
  • See how to use the JMP Marketplace – Free tools to expand JMP capabilities. Register. July 10, 2 pm US Eastern Time.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
Jackie_
Level VI

Count number of rows in column, with matching character

Hi,

 

I'm trying to wirte a jsl code to get a count of the number of strings(rows) with a certain specified characters at a certain position within the column.

Eg. I want to get the count of the number of the rows containing sting "1" between the rows containing only three "P" characters

In this case, the row count would be 26. Please advice.

Jackie__0-1686845224672.png

 

Thanks,

Jackie

1 ACCEPTED SOLUTION

Accepted Solutions
Craige_Hales
Super User

Re: Count number of rows in column, with matching character

Here's a pattern matching idea

dt = Open( "/Z:/data table_sample.jmp" );
// turn the column into a string
txt = Concat Items( dt:column1 << getvalues, "" );
Pat Match(
	txt,
	"PPP" + Pat Pos() >> pos + Pat Span( "1" ) >> run + "PPP" +
	Pat Test(
		Show( pos + 1, Length( run ) );
		0; // this time the test fails to make it retry the match
	)
);

pos + 1 = 30;
Length(run) = 26;
pos + 1 = 88;
Length(run) = 26;

 

Craige

View solution in original post

5 REPLIES 5
jthi
Super User

Re: Count number of rows in column, with matching character

Where do you want to store those results? Can there be more or less than 3Ps in row and if there can be, should the calculation for those Ps be ignored?

-Jarmo
Jackie_
Level VI

Re: Count number of rows in column, with matching character

@jthi 

So it can be store in a variable maybe N_rows  something. No, it has to be 3Ps in a row and yes ignore the calculate for other Ps

Craige_Hales
Super User

Re: Count number of rows in column, with matching character

Here's a pattern matching idea

dt = Open( "/Z:/data table_sample.jmp" );
// turn the column into a string
txt = Concat Items( dt:column1 << getvalues, "" );
Pat Match(
	txt,
	"PPP" + Pat Pos() >> pos + Pat Span( "1" ) >> run + "PPP" +
	Pat Test(
		Show( pos + 1, Length( run ) );
		0; // this time the test fails to make it retry the match
	)
);

pos + 1 = 30;
Length(run) = 26;
pos + 1 = 88;
Length(run) = 26;

 

Craige
txnelson
Super User

Re: Count number of rows in column, with matching character

Craige,

Neat solution

Jim
Jackie_
Level VI

Re: Count number of rows in column, with matching character

Thanks Craige!

Recommended Articles