<?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 How to determine if column is non-zero and all-zero in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-determine-if-column-is-non-zero-and-all-zero/m-p/592500#M79650</link>
    <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a data set that has an all-zero column. However, its column value is not consistent in having an all-zero value. How can I determine if it has an all-zero and when it has normal values? I just need it to create an if condition.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Expected output:&lt;/P&gt;&lt;P&gt;if Col1 is all-zero =&amp;gt; print ("Col1 is all zero"), print ("Col1 is non-zero);&lt;/P&gt;</description>
    <pubDate>Fri, 09 Jun 2023 16:05:41 GMT</pubDate>
    <dc:creator>UserID16644</dc:creator>
    <dc:date>2023-06-09T16:05:41Z</dc:date>
    <item>
      <title>How to determine if column is non-zero and all-zero</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-determine-if-column-is-non-zero-and-all-zero/m-p/592500#M79650</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a data set that has an all-zero column. However, its column value is not consistent in having an all-zero value. How can I determine if it has an all-zero and when it has normal values? I just need it to create an if condition.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Expected output:&lt;/P&gt;&lt;P&gt;if Col1 is all-zero =&amp;gt; print ("Col1 is all zero"), print ("Col1 is non-zero);&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 16:05:41 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-determine-if-column-is-non-zero-and-all-zero/m-p/592500#M79650</guid>
      <dc:creator>UserID16644</dc:creator>
      <dc:date>2023-06-09T16:05:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine if column is non-zero and all-zero</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-determine-if-column-is-non-zero-and-all-zero/m-p/592531#M79652</link>
      <description>&lt;P&gt;Here are a few different ways to look code he solution&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

If( Col Std Dev( :col1 ) == 0 &amp;amp; Col Sum( :col1 ) == 0,
	Print( "Col1 is all zero" ),
	Print( "Col1 is non-zero" )
);

dt = Current Data Table();
y = If( Length( Loc( dt[0, 6], 0 ) ) == N Rows( dt ),
	Print( "Col1 is all zero" ),
	Print( "Col1 is non-zero" )
);

y = If( Length( Loc( dt:col1 &amp;lt;&amp;lt; get as matrix, 0 ) ) == N Rows( dt ),
	Print( "Col1 is all zero" ),
	Print( "Col1 is non-zero" )
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Jan 2023 09:35:35 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-determine-if-column-is-non-zero-and-all-zero/m-p/592531#M79652</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2023-01-24T09:35:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine if column is non-zero and all-zero</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-determine-if-column-is-non-zero-and-all-zero/m-p/592727#M79669</link>
      <description>&lt;P&gt;Here is another way:&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 = Open( "$SAMPLE_DATA/Big Class.jmp" );

// create a column with all zeros
dt &amp;lt;&amp;lt; New Column( "Zero", "Numeric", "Continuous", Values( J( N Row( dt ), 1, 0 ) ) );

// determine if column contains all zeros
If( Sum( (:age &amp;lt;&amp;lt; Get As Matrix) == J( N Row( dt ), 1, 0 ) ) != 0, Print( "Col is all zero" ), Print( "Col is non-zero" ) );
If( Sum( (:Zero &amp;lt;&amp;lt; Get As Matrix) == J( N Row( dt ), 1, 0 ) ) != 0, Print( "Col is all zero" ), Print( "Col is non-zero" ) );&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Jan 2023 17:03:36 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-determine-if-column-is-non-zero-and-all-zero/m-p/592727#M79669</guid>
      <dc:creator>Mark_Bailey</dc:creator>
      <dc:date>2023-01-24T17:03:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine if column is non-zero and all-zero</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-determine-if-column-is-non-zero-and-all-zero/m-p/592819#M79679</link>
      <description>&lt;P&gt;Few more.&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 = New Table("table",
	Add Rows(3),
	New Column("A", Numeric, "Continuous", Format("Best", 12), Set Values([0, 1, 0])),
	New Column("B", Numeric, "Continuous", Format("Best", 12), Set Values([0, 0, 0])),
	New Column("C", Numeric, "Continuous", Format("Best", 12), Set Values([1, 0, -1])),
	New Column("D", Numeric, "Continuous", Format("Best", 12), Set Values([0, 0, .]))
);

// If you have columns with missing values (:D in this case) it might yield weird results
// you might have to use IfMZ instead of If or in some cases use different calculations
// depending on how you want to see missing values (as zero or "normal" value)

For Each({col}, {:A, :B, :C, :D},
	Show(col);
	Print("min-max");
	If(Col Max(col) == Col Min(col) &amp;amp; Col Max(col) == 0,
		Print("Col is all zero")
	, // else
		Print("Col is non-zero")
	);
	
	Print("all");
	If(All(col &amp;lt;&amp;lt; get as matrix == 0), 
		Print("Col is all zero")
	, // else
		Print("Col is non-zero")
	);

	Print("any");
	If(Any(col &amp;lt;&amp;lt; get as matrix),
		Print("Col is non-zero")
	, // else
		Print("Col is all zero")
	);
	Write("\!N");
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This might be out of scope but different methods might handle missing values differently and if you happen to have column properties set (missing value codes for example), those might also have an effect on the results and you might have to use &lt;A href="https://www.jmp.com/support/help/en/16.2/#page/jmp/row-functions-2.shtml#ww5085582" target="_self"&gt;Col Stored Value(&amp;lt;dt&amp;gt;, col, &amp;lt;row&amp;gt;)&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jan 2023 19:05:05 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-determine-if-column-is-non-zero-and-all-zero/m-p/592819#M79679</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-01-24T19:05:05Z</dc:date>
    </item>
  </channel>
</rss>

