<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Function to Count Rows Within Spec in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Function-to-Count-Rows-Within-Spec/m-p/370879#M62073</link>
    <description>&lt;P&gt;Thank you everyone. I have explored all three categories of methods. I then realized I could have made things a bit easier for myself by using something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt0 = current data table();
	dt0 &amp;lt;&amp;lt; clear row states;

count_in_spec = Function( { col, lsl, usl },
	a=0; //pass count
	b=0; //all count
	
	cola = dt0:col &amp;lt;&amp;lt; get as matrix;
	for( i = 1, i &amp;lt;= N Rows( cola ), i++,
			if( cola[i] &amp;gt;= lsl &amp;amp; cola[i] &amp;lt;= usl, a++ );
			if( not(ismissing( cola[i] )), b++ );
	);

	pctpass = 100*a/b;
	pctfail = 100 - pctpass;
	
	evallist({a, b, pctpass, pctfail});
);



colp = "param1";

results = count_in_spec(colp, 0.15, 0.30 );
	countpass = results[1];
	countall = results[2];
	pctpass = results[3];
	pctfail = results[4];

show(countpass);
show(countall);
show(pctpass);
show(pctfail);


colp = "param2";

results = count_in_spec(colp, 0.15, 0.30);
	countpass = results[1];
	countall = results[2];
	pctpass = results[3];
	pctfail = results[4];

show(countpass);
show(countall);
show(pctpass);
show(pctfail);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The syntax for extracting LSL and USL properties from a column will be useful.&lt;/P&gt;</description>
    <pubDate>Wed, 24 Mar 2021 01:14:14 GMT</pubDate>
    <dc:creator>LaserGuy</dc:creator>
    <dc:date>2021-03-24T01:14:14Z</dc:date>
    <item>
      <title>Function to Count Rows Within Spec</title>
      <link>https://community.jmp.com/t5/Discussions/Function-to-Count-Rows-Within-Spec/m-p/369867#M61956</link>
      <description>&lt;P&gt;I want to create a function that reads in a column, checks the number in each row on whether it is within spec, and output the passing count/total count/percentages.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what I have:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;count_in_spec = Function( { col, lsl, usl },
	a=0; //pass count
	b=0; //all count
	for( i = 1, i &amp;lt;= N Rows(col), i++,
		if( col[i] &amp;gt;= lsl &amp;amp; col[i] &amp;lt;= usl, a++ );
		if( not(ismissing(col[i])), b++ );
	);
	pctpass = 100*a/b;
	pctfail = 100 - pctpass;
	
	evallist({a, b, pctpass, pctfail});
);


dt0 = current data table();
colp = dt0:name("param") &amp;lt;&amp;lt; get as matrix;

results = count_in_spec(colp, 0.15, 0.30 );
	countpass = results[1];
	countall = results[2];
	pctpass = results[3];
	pctfail = results[4];&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;While this works, I don't like the fact that I need to use "get as matrix". It's a bit clunky.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like a function that works simply by writing:&lt;/P&gt;&lt;P&gt;results = count_in_spec( "param name", lsl, usl);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How would I modify my function so it can work this way?&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 22:09:01 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Function-to-Count-Rows-Within-Spec/m-p/369867#M61956</guid>
      <dc:creator>LaserGuy</dc:creator>
      <dc:date>2023-06-09T22:09:01Z</dc:date>
    </item>
    <item>
      <title>Re: Function to Count Rows Within Spec</title>
      <link>https://community.jmp.com/t5/Discussions/Function-to-Count-Rows-Within-Spec/m-p/369891#M61958</link>
      <description>&lt;P&gt;EDIT: I can no longer recommend this solution--use MS's: it shows a way to do this using a column formula; not only should it run faster, but column formulas also have the benefit of supporting grouping variables.&lt;/P&gt;
&lt;P&gt;-Brady&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use the built-in matrix functions for this. I use &amp;lt;&amp;lt;get as matrix within the function, but I'm not sure how you'd avoid that without making the script more cumbersome.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;Brady&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = astable(J(1000, 1, randomnormal(0,3)), &amp;lt;&amp;lt;column names ({x}));
	
count_in_spec = function({col, lsl, usl},
	{default local},
	vals = column(dt, col) &amp;lt;&amp;lt; get as matrix;
	vals = vals[loc(!is missing (vals))];		//remove missing rows
	nr = nrow(vals);							//get number of rows
	nPass = sum(lsl &amp;lt;= vals &amp;lt;= usl);			
	evallist({nPass, nr, 100*nPass/nr, 100*(nr-nPass)/nr})  //be sure to EVAL the list!
);

//test it out...
{countpass, countall, pctpass, pctfail} = count_in_spec("x", -3, 4);

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 21 Mar 2021 20:20:10 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Function-to-Count-Rows-Within-Spec/m-p/369891#M61958</guid>
      <dc:creator>brady_brady</dc:creator>
      <dc:date>2021-03-21T20:20:10Z</dc:date>
    </item>
    <item>
      <title>Re: Function to Count Rows Within Spec</title>
      <link>https://community.jmp.com/t5/Discussions/Function-to-Count-Rows-Within-Spec/m-p/369905#M61960</link>
      <description>&lt;P&gt;Using the Get Rows Where() function should get you want you want&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sr1.PNG" style="width: 142px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/31414iE1417A27104BE0E4/image-size/large?v=v2&amp;amp;px=999" role="button" title="sr1.PNG" alt="sr1.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/semiconductor capability.jmp" );

count_in_spec = Function( {col, lsl, usl},
	result = N Rows( dt &amp;lt;&amp;lt; get rows where( lsl &amp;lt;= As Column( dt, col ) &amp;lt;= usl ) )
);

colNames = dt &amp;lt;&amp;lt; get column names(string, continuous);

resultColList = {};
resultCountList = {};

For(i=1,i&amp;lt;= 10 /*Nitems(colNames)*/,i++,
	specs = column(dt,colNames[i]) &amp;lt;&amp;lt; get property("spec limits");
	If(isMissing(try(specs["LSL"],.))==0 &amp;amp; isMissing(try(specs["USL"],.))==0,
		result = count_in_spec(colNames[i],specs["LSL"],specs["USL"]);
		insert into(resultColList,colNames[i]);
		insert into(resultCountList,result)
	)
);

new window("Results",
	outline box("In Spec Report",
		Table Box(
			string col box("Column", resultColList),
			number col box("Count", resultCountList)
		)
	)
);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Mar 2021 22:13:42 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Function-to-Count-Rows-Within-Spec/m-p/369905#M61960</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-03-19T22:13:42Z</dc:date>
    </item>
    <item>
      <title>Re: Function to Count Rows Within Spec</title>
      <link>https://community.jmp.com/t5/Discussions/Function-to-Count-Rows-Within-Spec/m-p/369924#M61963</link>
      <description>&lt;P&gt;The Col Stat() functions are often efficient for directly summarizing table data, also with conditionals involved. Here's an example without the need for a matrix step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

count_in_spec = Function( {col, lsl, usl},
	{default local},
	a = Col Sum( lsl &amp;lt; As Column( col ) &amp;lt; usl );
	b = Col Number( col );
	pctpass = 100 * a / b;
	pctfail = 100 - pctpass;
	Eval List( {a, b, pctpass, pctfail} );
);

results = count_in_spec( Column( dt, "height" ), 55, 70 );
countpass = results[1];
countall = results[2];
pctpass = results[3];
pctfail = results[4];&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Mar 2021 22:59:20 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Function-to-Count-Rows-Within-Spec/m-p/369924#M61963</guid>
      <dc:creator>ms</dc:creator>
      <dc:date>2021-03-19T22:59:20Z</dc:date>
    </item>
    <item>
      <title>Re: Function to Count Rows Within Spec</title>
      <link>https://community.jmp.com/t5/Discussions/Function-to-Count-Rows-Within-Spec/m-p/370879#M62073</link>
      <description>&lt;P&gt;Thank you everyone. I have explored all three categories of methods. I then realized I could have made things a bit easier for myself by using something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt0 = current data table();
	dt0 &amp;lt;&amp;lt; clear row states;

count_in_spec = Function( { col, lsl, usl },
	a=0; //pass count
	b=0; //all count
	
	cola = dt0:col &amp;lt;&amp;lt; get as matrix;
	for( i = 1, i &amp;lt;= N Rows( cola ), i++,
			if( cola[i] &amp;gt;= lsl &amp;amp; cola[i] &amp;lt;= usl, a++ );
			if( not(ismissing( cola[i] )), b++ );
	);

	pctpass = 100*a/b;
	pctfail = 100 - pctpass;
	
	evallist({a, b, pctpass, pctfail});
);



colp = "param1";

results = count_in_spec(colp, 0.15, 0.30 );
	countpass = results[1];
	countall = results[2];
	pctpass = results[3];
	pctfail = results[4];

show(countpass);
show(countall);
show(pctpass);
show(pctfail);


colp = "param2";

results = count_in_spec(colp, 0.15, 0.30);
	countpass = results[1];
	countall = results[2];
	pctpass = results[3];
	pctfail = results[4];

show(countpass);
show(countall);
show(pctpass);
show(pctfail);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The syntax for extracting LSL and USL properties from a column will be useful.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Mar 2021 01:14:14 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Function-to-Count-Rows-Within-Spec/m-p/370879#M62073</guid>
      <dc:creator>LaserGuy</dc:creator>
      <dc:date>2021-03-24T01:14:14Z</dc:date>
    </item>
    <item>
      <title>Re: Function to Count Rows Within Spec</title>
      <link>https://community.jmp.com/t5/Discussions/Function-to-Count-Rows-Within-Spec/m-p/780491#M96258</link>
      <description>&lt;P&gt;Just imagine how useful&amp;nbsp;&lt;LI-MESSAGE title="🙏 is in spec (value)" uid="774331" url="https://community.jmp.com/t5/JMP-Wish-List/is-in-spec-value/m-p/774331#U774331" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-idea-thread lia-fa-icon lia-fa-idea lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp; will be.&lt;BR /&gt;With the new functionality any user can do the calculation in Graph Builder !&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hogi_0-1723193995962.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/66992iC1B3B931E3EEA28E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="hogi_0-1723193995962.png" alt="hogi_0-1723193995962.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Aug 2024 09:00:58 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Function-to-Count-Rows-Within-Spec/m-p/780491#M96258</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2024-08-09T09:00:58Z</dc:date>
    </item>
  </channel>
</rss>

