<?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: Count number of Non Zeros and Non Missing by row in a dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Count-number-of-Non-Zeros-and-Non-Missing-by-row-in-a-dataset/m-p/936348#M368066</link>
    <description>&lt;P&gt;If you just want to count within the observation then why do you have the BY statement and why do you reference FIRST.NAME?&lt;/P&gt;</description>
    <pubDate>Fri, 19 Jul 2024 13:11:53 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-07-19T13:11:53Z</dc:date>
    <item>
      <title>Count number of Non Zeros and Non Missing by row in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-number-of-Non-Zeros-and-Non-Missing-by-row-in-a-dataset/m-p/936334#M368063</link>
      <description>&lt;P&gt;Hello there,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to count the number of non 0's and non missing values row-wise.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, I have this dataset:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input name $ A B C D E F G H I J K L;
cards;
AAA 100 50 30 55 66 90 100 110 150 22 0 .
BBB 200 70 30 90 21 80 200 321 456 67 . 0
CCC 300 40 60 40 43 30 300 455 210 57 304 310
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and I want a column that shows the number of non 0s and non missing per each row:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input name $ A B C D E F G H I J K L No_Of_Non0_or_Nonmissing;
cards;
AAA 100 50 30 55 66 90 100 110 150 22 0 . 10
BBB 200 70 30 90 21 80 200 321 456 67 . 0 10
CCC 300 40 60 40 43 30 300 455 210 57 304 310 12
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I have created the following but it is not working as expected:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data attempt;
set have;
array s {*} _numeric_;

by name;
	do _i_=1 to dim(s);

		if s[_i_] not in (.,0) then do;
			if first.name then No_Of_Non0_or_Nonmissing+ 1;
			else No_Of_Non0_or_Nonmissing=0;
		end;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As you may see it adds the non 0s and non missing values to the next row:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Zatere_0-1721388507197.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/98512i64A1D11373B20CCF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Zatere_0-1721388507197.png" alt="Zatere_0-1721388507197.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Any help would be much appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2024 11:31:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-number-of-Non-Zeros-and-Non-Missing-by-row-in-a-dataset/m-p/936334#M368063</guid>
      <dc:creator>Zatere</dc:creator>
      <dc:date>2024-07-19T11:31:38Z</dc:date>
    </item>
    <item>
      <title>Re: Count number of Non Zeros and Non Missing by row in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-number-of-Non-Zeros-and-Non-Missing-by-row-in-a-dataset/m-p/936337#M368064</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have;
	array x[*] a--l;
	do _i=1 to dim(x);
		/* The result of the expression is 0 if FALSE, 1 if TRUE */
		No_Of_Non0_or_Nonmissing=SUM(No_Of_Non0_or_Nonmissing,x[_i]&amp;gt;0);
	end;
	/* Get rid of the loop counter */
	drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Jul 2024 12:08:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-number-of-Non-Zeros-and-Non-Missing-by-row-in-a-dataset/m-p/936337#M368064</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2024-07-19T12:08:07Z</dc:date>
    </item>
    <item>
      <title>Re: Count number of Non Zeros and Non Missing by row in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-number-of-Non-Zeros-and-Non-Missing-by-row-in-a-dataset/m-p/936338#M368065</link>
      <description>&lt;P&gt;You could use something like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ZERO_CNT = count( ' '||catx(' ', of A--L)||' ', ' 0 ');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For non-missing values, use the N() function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2024 12:23:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-number-of-Non-Zeros-and-Non-Missing-by-row-in-a-dataset/m-p/936338#M368065</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2024-07-19T12:23:14Z</dc:date>
    </item>
    <item>
      <title>Re: Count number of Non Zeros and Non Missing by row in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-number-of-Non-Zeros-and-Non-Missing-by-row-in-a-dataset/m-p/936348#M368066</link>
      <description>&lt;P&gt;If you just want to count within the observation then why do you have the BY statement and why do you reference FIRST.NAME?&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2024 13:11:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-number-of-Non-Zeros-and-Non-Missing-by-row-in-a-dataset/m-p/936348#M368066</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-07-19T13:11:53Z</dc:date>
    </item>
  </channel>
</rss>

