<?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: How to Count Zero Values If Whole Row Includes Zero Values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-Count-Zero-Values-If-Whole-Row-Includes-Zero-Values/m-p/274372#M54731</link>
    <description>&lt;P&gt;A simple solution is to use max and min functions...you need both to ensure all values are zero, as below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Looking at your data I think the end result should be three, not two, as per the code below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Comment out "if eof then..." if you want to keep each line.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Chris&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data Have;&lt;BR /&gt;Length Numeric1 8 Numeric2 8 Numeric3 8 Numeric4 8 Numeric5 8;&lt;BR /&gt;Infile Datalines Missover;&lt;BR /&gt;Input Numeric1 Numeric2 Numeric3 Numeric4 Numeric5;&lt;BR /&gt;Datalines;&lt;BR /&gt;0 0 0 0 0 /* Count 1*/&lt;BR /&gt;-1 0 0 0 -1&lt;BR /&gt;2 2 0 -2 -2&lt;BR /&gt;0 0 0 0 0 /* Count 2*/&lt;BR /&gt;-9 9 6 5 -11&lt;BR /&gt;0 0 0 0 0 /* Count 3*/&lt;BR /&gt;;&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;data want (keep = zero_count);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;set have end = eof;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;retain zero_count 0;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if max(of numeric1-numeric5) eq 0 and min(of numeric1-numeric5) eq 0 then&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;zero_count + 1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if eof then&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;output;&lt;BR /&gt;run;&lt;/P&gt;</description>
    <pubDate>Wed, 01 Jun 2016 14:48:56 GMT</pubDate>
    <dc:creator>rivieralad</dc:creator>
    <dc:date>2016-06-01T14:48:56Z</dc:date>
    <item>
      <title>How to Count Zero Values If Whole Row Includes Zero Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Count-Zero-Values-If-Whole-Row-Includes-Zero-Values/m-p/274370#M54729</link>
      <description>&lt;P&gt;Hello everybody,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a question for you. I want to get number of zero values if whole row has zero values. I prepared a sample code as below. I tried to do some methods and looked for the old discussion in this site but I couldn't find and create a solution. Can somebody help me, please?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Have;
Length Numeric1 8 Numeric2 8 Numeric3 8 Numeric4 8 Numeric5 8;
Infile Datalines Missover;
Input Numeric1 Numeric2 Numeric3 Numeric4 Numeric5;
Datalines;
0 0 0 0 0 /* Count 1*/
-1 0 0 0 -1
2 2 0 -2 -2
0 0 0 0 0
-9 9 6 5 -11
0 0 0 0 0 /* Count 2*/
;
Run;
ODS OUTPUT Summary=Want2 (Rename=(Mean=_Mean));

Proc Means Data=Have Mean StackOdsOutput;
Var Numeric1-Numeric5;
Run;

PROC SQL;
Create Table Want As
Select Count(_Mean) As CountOfVariables From Want2
Where _Mean=0;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In my foregoing sample, it should count "2" value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jun 2016 14:33:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Count-Zero-Values-If-Whole-Row-Includes-Zero-Values/m-p/274370#M54729</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2016-06-01T14:33:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to Count Zero Values If Whole Row Includes Zero Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Count-Zero-Values-If-Whole-Row-Includes-Zero-Values/m-p/274372#M54731</link>
      <description>&lt;P&gt;A simple solution is to use max and min functions...you need both to ensure all values are zero, as below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Looking at your data I think the end result should be three, not two, as per the code below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Comment out "if eof then..." if you want to keep each line.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Chris&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data Have;&lt;BR /&gt;Length Numeric1 8 Numeric2 8 Numeric3 8 Numeric4 8 Numeric5 8;&lt;BR /&gt;Infile Datalines Missover;&lt;BR /&gt;Input Numeric1 Numeric2 Numeric3 Numeric4 Numeric5;&lt;BR /&gt;Datalines;&lt;BR /&gt;0 0 0 0 0 /* Count 1*/&lt;BR /&gt;-1 0 0 0 -1&lt;BR /&gt;2 2 0 -2 -2&lt;BR /&gt;0 0 0 0 0 /* Count 2*/&lt;BR /&gt;-9 9 6 5 -11&lt;BR /&gt;0 0 0 0 0 /* Count 3*/&lt;BR /&gt;;&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;data want (keep = zero_count);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;set have end = eof;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;retain zero_count 0;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if max(of numeric1-numeric5) eq 0 and min(of numeric1-numeric5) eq 0 then&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;zero_count + 1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if eof then&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;output;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jun 2016 14:48:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Count-Zero-Values-If-Whole-Row-Includes-Zero-Values/m-p/274372#M54731</guid>
      <dc:creator>rivieralad</dc:creator>
      <dc:date>2016-06-01T14:48:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to Count Zero Values If Whole Row Includes Zero Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Count-Zero-Values-If-Whole-Row-Includes-Zero-Values/m-p/274374#M54733</link>
      <description>&lt;P&gt;I think that you'll need to add an additional variable to your&amp;nbsp;have set.&lt;/P&gt;
&lt;P&gt;Also why is the 4th line not counted? If has 5 zero values.&lt;/P&gt;
&lt;P&gt;You do not specify what to do if if 4 of the 5 are zero and the 5th is missing or other combinations of 0 and missing.&lt;/P&gt;
&lt;P&gt;This adds a variable that is 1 when all 5 values are valued 0 and 0 other wise. Sum it to get a count of the zero rows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or you could conditionally assign the 1 and leave missing otherwise to use N to count.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Have;
   Length Numeric1 8 Numeric2 8 Numeric3 8 Numeric4 8 Numeric5 8;
   Infile Datalines Missover;
   Input Numeric1 Numeric2 Numeric3 Numeric4 Numeric5;
   CountZero = (n(of Numeric:)=5)*(max(of Numeric:)=0)*(Min(of numeric:)=0);
Datalines;
0 0 0 0 0 
-1 0 0 0 -1
2 2 0 -2 -2
0 0 0 0 0
-9 9 6 5 -11
0 0 0 0 0 
;
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Jun 2016 14:52:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Count-Zero-Values-If-Whole-Row-Includes-Zero-Values/m-p/274374#M54733</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-06-01T14:52:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to Count Zero Values If Whole Row Includes Zero Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Count-Zero-Values-If-Whole-Row-Includes-Zero-Values/m-p/274397#M54746</link>
      <description>&lt;P&gt;Here's a similar&amp;nbsp;solution, counting observations with zeros in all variables whose names start with "Num":&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(keep=c0);
set have end=eof;
c0+ ~uss(of Num:, nmiss(of Num:));
if eof;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Jun 2016 15:45:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Count-Zero-Values-If-Whole-Row-Includes-Zero-Values/m-p/274397#M54746</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-06-01T15:45:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to Count Zero Values If Whole Row Includes Zero Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Count-Zero-Values-If-Whole-Row-Includes-Zero-Values/m-p/274423#M54749</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;Rivieralad, y&lt;/SPAN&gt;es you are right, the result shoud be three and your code provides me desired output. I also get the percentage value as below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Have;
Length Numeric1 8 Numeric2 8 Numeric3 8 Numeric4 8 Numeric5 8;
Infile Datalines Missover;
Input Numeric1 Numeric2 Numeric3 Numeric4 Numeric5;
Datalines;
0 0 0 0 0 /* Count 1*/
-1 0 0 0 -1
2 2 0 -2 -2
0 0 0 0 0 /* Count 2*/
-9 9 6 5 -11
0 0 0 0 0 /* Count 3*/
; 
Run;
 
Data Want(Keep=Zero_Count Percent) ; 
Set Have End=Eof;
Retain Zero_Count 0;
If Max(of numeric1-numeric5) eq 0 and Min(of numeric1-numeric5) eq 0 then
Zero_Count + 1;
Percent=Zero_Count/_n_; 
If eof Then 
Output;
run;
 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;FreelanceReinhard and ballardw also thank you for your responses&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jun 2016 17:10:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Count-Zero-Values-If-Whole-Row-Includes-Zero-Values/m-p/274423#M54749</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2016-06-01T17:10:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to Count Zero Values If Whole Row Includes Zero Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Count-Zero-Values-If-Whole-Row-Includes-Zero-Values/m-p/274431#M54751</link>
      <description>&lt;P&gt;be aware that solution will count&lt;/P&gt;
&lt;P&gt;0 . . . .&lt;/P&gt;
&lt;P&gt;0 0 . . .&lt;/P&gt;
&lt;P&gt;0 0 0 . .&lt;/P&gt;
&lt;P&gt;0 0 0 0 .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you never have missing values or that is the desired case then okay. But you should be aware for when you reuse this code elsewhere and the data condition changes you may get undesired results.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jun 2016 17:21:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Count-Zero-Values-If-Whole-Row-Includes-Zero-Values/m-p/274431#M54751</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-06-01T17:21:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to Count Zero Values If Whole Row Includes Zero Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Count-Zero-Values-If-Whole-Row-Includes-Zero-Values/m-p/274433#M54752</link>
      <description>&lt;P&gt;Thank you ballardw&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't have missing values should I still consider to my output?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jun 2016 17:24:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Count-Zero-Values-If-Whole-Row-Includes-Zero-Values/m-p/274433#M54752</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2016-06-01T17:24:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to Count Zero Values If Whole Row Includes Zero Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Count-Zero-Values-If-Whole-Row-Includes-Zero-Values/m-p/274437#M54755</link>
      <description>&lt;P&gt;No missing values then you should be okay. I just wanted you to realize that later you might run into an issue if you do have missing values.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jun 2016 17:33:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Count-Zero-Values-If-Whole-Row-Includes-Zero-Values/m-p/274437#M54755</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-06-01T17:33:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to Count Zero Values If Whole Row Includes Zero Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Count-Zero-Values-If-Whole-Row-Includes-Zero-Values/m-p/274488#M54791</link>
      <description>&lt;P&gt;Thank you for your attention, I'll consider it&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jun 2016 21:22:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Count-Zero-Values-If-Whole-Row-Includes-Zero-Values/m-p/274488#M54791</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2016-06-01T21:22:55Z</dc:date>
    </item>
  </channel>
</rss>

