<?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 within arrays in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Count-within-arrays/m-p/781444#M20162</link>
    <description>&lt;P&gt;What if I want to count non missing numeric values withing the array?&lt;/P&gt;</description>
    <pubDate>Sat, 20 Nov 2021 12:01:37 GMT</pubDate>
    <dc:creator>Emet</dc:creator>
    <dc:date>2021-11-20T12:01:37Z</dc:date>
    <item>
      <title>Count within arrays</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Count-within-arrays/m-p/346638#M10306</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;In a data step in which I have defined an array I can use the sum function, but the count function doesn't work. How can I count the number of values that are not zero within an array?&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SUM_ARRAY = sum(of A1-A20); - Works&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; COUNT_ARRAY = count(of A1-A20);&amp;nbsp; Yields the following error: "The COUNT function call has too many arguments"&lt;/P&gt;</description>
      <pubDate>Mon, 03 Apr 2017 12:03:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Count-within-arrays/m-p/346638#M10306</guid>
      <dc:creator>pablorodriguez1</dc:creator>
      <dc:date>2017-04-03T12:03:20Z</dc:date>
    </item>
    <item>
      <title>Re: Count within arrays</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Count-within-arrays/m-p/346647#M10307</link>
      <description>&lt;P&gt;The COUNT function is intended for character strings.&amp;nbsp; Perhaps you are thinking of the N function?&amp;nbsp; (If not, what are you trying to accomplish?)&lt;/P&gt;</description>
      <pubDate>Mon, 03 Apr 2017 12:45:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Count-within-arrays/m-p/346647#M10307</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-04-03T12:45:58Z</dc:date>
    </item>
    <item>
      <title>Re: Count within arrays</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Count-within-arrays/m-p/346682#M10308</link>
      <description>&lt;P&gt;I don't even see the array mentioned in the question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would likely start with something like this:&lt;/P&gt;
&lt;PRE&gt;array values a1-a20;
sum_array = sum(of values(*));
do i= 1 to dim(values);
   Count_array= sum(count_array,(values[i] ne 0));
end;&lt;/PRE&gt;
&lt;P&gt;However this will count values that are missing as well. Is that the desired behavior?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Apr 2017 14:22:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Count-within-arrays/m-p/346682#M10308</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-04-03T14:22:40Z</dc:date>
    </item>
    <item>
      <title>Re: Count within arrays</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Count-within-arrays/m-p/346716#M10309</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;I don't think it is possible?

Here is what I consider minimal code:

data tst;
array values a1-a5 (10 0 23 15 43);
do over values;
 cnt + (values ne 0);
end;
run;quit;

Up to 40 obs WORK.TST total obs=1

                                      SUM_
Obs    A1    A2    A3    A4    A5    ARRAY    CNT

 1     10     0    23    15    43      91      4

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 03 Apr 2017 15:16:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Count-within-arrays/m-p/346716#M10309</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2017-04-03T15:16:23Z</dc:date>
    </item>
    <item>
      <title>Re: Count within arrays</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Count-within-arrays/m-p/346728#M10310</link>
      <description>&lt;P&gt;&lt;CODE&gt;COUNT&lt;/CODE&gt; can be coerced to do this, if your data is agreeable. I'm not sure it's better than the loop operation timewise or structurally, but it's at least an interesting solution.&lt;/P&gt;
&lt;P&gt;Basically we delimit the data by &lt;CODE&gt;;&lt;/CODE&gt; including starting and ending it with the delimiter, then count the number of &lt;CODE&gt;;0;&lt;/CODE&gt;, and subtract from the total.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;data _null_;
  call streaminit(7);
  array a[20];
  do _i = 1 to 20;
    a[_i] = max(0,rand('Uniform')-0.3);
  end;
  put a[*]=;
  nonzero = dim(a) - count(';'||catx(';',of a[*])||';',';0;');
  put nonzero=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(This was cross-posted to/from Stack Overflow:&amp;nbsp;&lt;A href="http://stackoverflow.com/questions/43184156/sas-count-within-arrays" target="_blank"&gt;http://stackoverflow.com/questions/43184156/sas-count-within-arrays&lt;/A&gt;)&lt;/P&gt;</description>
      <pubDate>Mon, 03 Apr 2017 15:50:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Count-within-arrays/m-p/346728#M10310</guid>
      <dc:creator>snoopy369</dc:creator>
      <dc:date>2017-04-03T15:50:58Z</dc:date>
    </item>
    <item>
      <title>Re: Count within arrays</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Count-within-arrays/m-p/781444#M20162</link>
      <description>&lt;P&gt;What if I want to count non missing numeric values withing the array?&lt;/P&gt;</description>
      <pubDate>Sat, 20 Nov 2021 12:01:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Count-within-arrays/m-p/781444#M20162</guid>
      <dc:creator>Emet</dc:creator>
      <dc:date>2021-11-20T12:01:37Z</dc:date>
    </item>
    <item>
      <title>Re: Count within arrays</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Count-within-arrays/m-p/781445#M20163</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/407246"&gt;@Emet&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;What if I want to count non missing numeric values withing the array?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/407246"&gt;@Emet&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It would really be much better if you started a new thread and described your problem completely, from the beginning. I would be happy to help you if you did this.&lt;/P&gt;</description>
      <pubDate>Sat, 20 Nov 2021 12:03:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Count-within-arrays/m-p/781445#M20163</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-11-20T12:03:42Z</dc:date>
    </item>
    <item>
      <title>Re: Count within arrays</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Count-within-arrays/m-p/781446#M20164</link>
      <description>&lt;P&gt;Thank you for prompt response. I will start a new thread.&lt;/P&gt;</description>
      <pubDate>Sat, 20 Nov 2021 12:06:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Count-within-arrays/m-p/781446#M20164</guid>
      <dc:creator>Emet</dc:creator>
      <dc:date>2021-11-20T12:06:14Z</dc:date>
    </item>
  </channel>
</rss>

