<?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 Deleting Columns with N Null Row Values in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Deleting-Columns-with-N-Null-Row-Values/m-p/517589#M74386</link>
    <description>&lt;P&gt;I have a table of values with each column being an instrument and each row being a time. Some instruments have not had data recorded at enough time values in order for me to fit a meaningful model.&lt;/P&gt;&lt;P&gt;I am attempting to use a loop to allow me to cycle through each column in turn and check the number of values.&lt;/P&gt;&lt;P&gt;I have some code which find the number of values for column 80.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;col_a = Column(dt_2, 80);
val_mat = col_a &amp;lt;&amp;lt; Get Values;
y = sum(!is missing(val_mat));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am attempting to adapt this code into a loop for each column in turn and delete columns with too few values.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;N_loop = N Cols(dt_2);
i_loop = 2;
While (i_loop &amp;lt;= N_loop,
	col_loop = Column(dt_2, i_loop),
	val_loop = col_loop &amp;lt;&amp;lt; Get Values,
	y_loop = sum(!is missing(val_loop)),
	If(y_loop &amp;lt;= 8,
		dt_2 &amp;lt;&amp;lt; Delete Columns( i_loop ),
	);
	i_temp+=1,
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The error message says too many arguments.&lt;/P&gt;</description>
    <pubDate>Tue, 05 Jul 2022 09:05:35 GMT</pubDate>
    <dc:creator>Jemster</dc:creator>
    <dc:date>2022-07-05T09:05:35Z</dc:date>
    <item>
      <title>Deleting Columns with N Null Row Values</title>
      <link>https://community.jmp.com/t5/Discussions/Deleting-Columns-with-N-Null-Row-Values/m-p/517589#M74386</link>
      <description>&lt;P&gt;I have a table of values with each column being an instrument and each row being a time. Some instruments have not had data recorded at enough time values in order for me to fit a meaningful model.&lt;/P&gt;&lt;P&gt;I am attempting to use a loop to allow me to cycle through each column in turn and check the number of values.&lt;/P&gt;&lt;P&gt;I have some code which find the number of values for column 80.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;col_a = Column(dt_2, 80);
val_mat = col_a &amp;lt;&amp;lt; Get Values;
y = sum(!is missing(val_mat));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am attempting to adapt this code into a loop for each column in turn and delete columns with too few values.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;N_loop = N Cols(dt_2);
i_loop = 2;
While (i_loop &amp;lt;= N_loop,
	col_loop = Column(dt_2, i_loop),
	val_loop = col_loop &amp;lt;&amp;lt; Get Values,
	y_loop = sum(!is missing(val_loop)),
	If(y_loop &amp;lt;= 8,
		dt_2 &amp;lt;&amp;lt; Delete Columns( i_loop ),
	);
	i_temp+=1,
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The error message says too many arguments.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jul 2022 09:05:35 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Deleting-Columns-with-N-Null-Row-Values/m-p/517589#M74386</guid>
      <dc:creator>Jemster</dc:creator>
      <dc:date>2022-07-05T09:05:35Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting Columns with N Null Row Values</title>
      <link>https://community.jmp.com/t5/Discussions/Deleting-Columns-with-N-Null-Row-Values/m-p/517640#M74390</link>
      <description>&lt;P&gt;Many ways to do this. One option is to use Col Number or Col N Missing and For Each (requires JMP16)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
//delete some values
dt[1::20, "name"] = "";
dt[1::30, "sex"] = "";
dt[1::40, "height"] = .;

wait(2);

row_count = N Rows(dt);
For Each({col_name}, dt &amp;lt;&amp;lt; Get Column Names("String"),
//  missing_vals = Col N Missing(Column(dt, col_name));
//	found_values = row_count - missing_vals;
	found_values = Col Number(Column(dt, col_name));
	If(found_values &amp;lt;= 8,
		dt &amp;lt;&amp;lt; Delete Column(col_name);
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Jul 2022 11:34:51 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Deleting-Columns-with-N-Null-Row-Values/m-p/517640#M74390</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2022-07-05T11:34:51Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting Columns with N Null Row Values</title>
      <link>https://community.jmp.com/t5/Discussions/Deleting-Columns-with-N-Null-Row-Values/m-p/517651#M74391</link>
      <description>&lt;P&gt;The reason there are too many arguments, is that, there is a second comma in the While() function.&lt;/P&gt;
&lt;P&gt;The structure of a While() function is&lt;/P&gt;
&lt;PRE&gt;While( testExpr, bodyExpr )&lt;/PRE&gt;
&lt;P&gt;Note: there are only 2 arguments to the function.&amp;nbsp; The test&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;i_loop &amp;lt;= N_loop&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and then the statements that are executed if the textExpr is true.&amp;nbsp; Your bodyExpr has commas after each statement, rather than semicolons.&amp;nbsp; Thus, making each statement a separate argument.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please do not just change the commas to semicolons and run this code.&amp;nbsp; There is a logic error, which will not allow the code to ever end.&amp;nbsp; i_loop and N_loop never change in value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is also a faster way to check for the number of valid values in a column.&amp;nbsp; Additionally, if you are deleting columns, and your N_loop value remains fixed, N_loop is no longer the correct number of columns in the data table, once one column is deleted.&amp;nbsp; It is best to work from the last column to the first column in such cases.&lt;/P&gt;
&lt;P&gt;Below is a rework of your script which will delete the columns where the number of valid data values is less than or equal to 8.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt_2 = Current Data Table();

N_loop = N Cols( dt_2 );

i_loop = 2;
While( N_loop &amp;gt; i_loop,
	If( Col Number( As Column( dt_2, N_loop ) ) &amp;lt;= 8,
		dt_2 &amp;lt;&amp;lt; Delete Columns( N_loop )
	);
	N_loop -= 1;
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;P.S.&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;&amp;nbsp;solution is a better solution.&amp;nbsp; &amp;nbsp;Your approach, with some corrections, does work.....so good job!&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jul 2022 12:25:12 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Deleting-Columns-with-N-Null-Row-Values/m-p/517651#M74391</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2022-07-05T12:25:12Z</dc:date>
    </item>
  </channel>
</rss>

