<?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: Do loop or array? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-or-array/m-p/12501#M1360</link>
    <description>does this look like an opportunity for the COUNT() function?&lt;BR /&gt;
First count all the columns in the macro environment - so counting all cols only once. On each row count occurrence of zeros to subtract from the all-cols count, leaving the non-zero count&lt;BR /&gt;
without any arrays&lt;BR /&gt;
Peter</description>
    <pubDate>Wed, 15 Jun 2011 17:27:37 GMT</pubDate>
    <dc:creator>Peter_C</dc:creator>
    <dc:date>2011-06-15T17:27:37Z</dc:date>
    <item>
      <title>Do loop or array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-or-array/m-p/12496#M1355</link>
      <description>I need count each obs non zero column,&lt;BR /&gt;
&lt;BR /&gt;
data like this:&lt;BR /&gt;
&lt;BR /&gt;
data a;&lt;BR /&gt;
 input m1-m12 @@;&lt;BR /&gt;
 cards;&lt;BR /&gt;
 0 1 4 0 0 0 0 0 0 0 0  0&lt;BR /&gt;
 1 0 0 0 0 0 0 0 0 0 0  0 &lt;BR /&gt;
 0 0 0 0 0 0 0 0 5 0 6 0&lt;BR /&gt;
 ;&lt;BR /&gt;
 run;&lt;BR /&gt;
&lt;BR /&gt;
How can I get non zeros fro each obs? &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Thanks in advance.</description>
      <pubDate>Mon, 13 Jun 2011 18:11:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-or-array/m-p/12496#M1355</guid>
      <dc:creator>QLi</dc:creator>
      <dc:date>2011-06-13T18:11:01Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop or array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-or-array/m-p/12497#M1356</link>
      <description>Generally with an array you use some type of do loop.  See my example below:&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data b;&lt;BR /&gt;
  set a;&lt;BR /&gt;
&lt;BR /&gt;
  array m(12);&lt;BR /&gt;
  zero=0;&lt;BR /&gt;
  do i=1 to dim(m);&lt;BR /&gt;
    zero=zero+(m&lt;I&gt; ne 0);&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;/I&gt;</description>
      <pubDate>Mon, 13 Jun 2011 20:00:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-or-array/m-p/12497#M1356</guid>
      <dc:creator>darrylovia</dc:creator>
      <dc:date>2011-06-13T20:00:27Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop or array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-or-array/m-p/12498#M1357</link>
      <description>Hello Darrylovia,&lt;BR /&gt;
&lt;BR /&gt;
I am sure the summing line of your code should look like:&lt;BR /&gt;
[pre]&lt;BR /&gt;
zero=zero+(m[i] ne 0);&lt;BR /&gt;
[/pre]&lt;BR /&gt;
This is a problem of this forum software. Please, see &lt;A href="http://support.sas.com/forums/thread.jspa?messageID=27609" target="_blank"&gt;http://support.sas.com/forums/thread.jspa?messageID=27609&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
Sincerely,&lt;BR /&gt;
SPR</description>
      <pubDate>Mon, 13 Jun 2011 20:31:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-or-array/m-p/12498#M1357</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2011-06-13T20:31:26Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop or array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-or-array/m-p/12499#M1358</link>
      <description>Friend,&lt;BR /&gt;
&lt;BR /&gt;
You can use the below code to count the number of zeros in an observation&lt;BR /&gt;
&lt;BR /&gt;
data a;&lt;BR /&gt;
input m1-m12;&lt;BR /&gt;
cards;&lt;BR /&gt;
0 1 4 0 0 0 0 0 0 0 0 0&lt;BR /&gt;
1 0 0 0 0 0 0 0 0 0 0 0&lt;BR /&gt;
0 0 0 0 0 0 0 0 5 0 6 0&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
data aa;&lt;BR /&gt;
set a;&lt;BR /&gt;
count = 0;&lt;BR /&gt;
array a[12] m1-m12;&lt;BR /&gt;
do i = 1 to 12;&lt;BR /&gt;
if a&lt;I&gt; = 0 then count+1;&lt;BR /&gt;
end;&lt;BR /&gt;
run;&lt;/I&gt;</description>
      <pubDate>Mon, 13 Jun 2011 20:31:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-or-array/m-p/12499#M1358</guid>
      <dc:creator>Ankitsas</dc:creator>
      <dc:date>2011-06-13T20:31:27Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop or array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-or-array/m-p/12500#M1359</link>
      <description>[pre]&lt;BR /&gt;
data a;&lt;BR /&gt;
input m1-m12;&lt;BR /&gt;
cards;&lt;BR /&gt;
0 1 4 0 0 0 0 0 0 0 0 0&lt;BR /&gt;
1 0 0 0 0 0 0 0 0 0 0 0&lt;BR /&gt;
0 0 0 0 0 0 0 0 5 0 6 0&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
data aa;&lt;BR /&gt;
set a;&lt;BR /&gt;
count=0;&lt;BR /&gt;
array a{*} m1-m12;&lt;BR /&gt;
do i = 1 to dim(a);&lt;BR /&gt;
if a{i} then count+1;&lt;BR /&gt;
end;&lt;BR /&gt;
drop i;&lt;BR /&gt;
run; &lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp

Message was edited by: Ksharp</description>
      <pubDate>Tue, 14 Jun 2011 04:53:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-or-array/m-p/12500#M1359</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-06-14T04:53:17Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop or array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-or-array/m-p/12501#M1360</link>
      <description>does this look like an opportunity for the COUNT() function?&lt;BR /&gt;
First count all the columns in the macro environment - so counting all cols only once. On each row count occurrence of zeros to subtract from the all-cols count, leaving the non-zero count&lt;BR /&gt;
without any arrays&lt;BR /&gt;
Peter</description>
      <pubDate>Wed, 15 Jun 2011 17:27:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-or-array/m-p/12501#M1360</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-06-15T17:27:37Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop or array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-or-array/m-p/12502#M1361</link>
      <description>Although I believe that the COUNT function relates only to SAS CHARACTER type variables.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Wed, 15 Jun 2011 17:31:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-or-array/m-p/12502#M1361</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2011-06-15T17:31:11Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop or array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-or-array/m-p/12503#M1362</link>
      <description>This is what I came up with using COUNT.  It could be made simpler if single digits were assumed.  It could also be done without the array using (of m1-m12) in the functions.  Six of one, half dozen of another, arrays are just fancy variables lists.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data test;&lt;BR /&gt;
   array m[12];&lt;BR /&gt;
   input m&lt;LI&gt;;&lt;BR /&gt;
   z = cats(';',catx(',;',of m&lt;/LI&gt;&lt;LI&gt;),',');&lt;BR /&gt;
   Not0 = n(of m&lt;/LI&gt;&lt;LI&gt;)-count(z,';0,');&lt;BR /&gt;
   cards;&lt;BR /&gt;
0 10 4 0 0 0 0 0 0 0 0 0&lt;BR /&gt;
1 0 0 0 0 0 0 0 0 0 0 0 &lt;BR /&gt;
0 0 0 0 0 0 0 0 5 0 6 0&lt;BR /&gt;
;;;;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]&lt;/LI&gt;</description>
      <pubDate>Wed, 15 Jun 2011 18:48:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-or-array/m-p/12503#M1362</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2011-06-15T18:48:55Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop or array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-or-array/m-p/12504#M1363</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is one way that does not require neither do loops or arrays.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;STRONG style="color: #000080; font-size: 10pt; font-family: Courier New;"&gt;data&lt;/STRONG&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt; one;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-family: Courier New; font-size: 10pt;"&gt;input&lt;/SPAN&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt; m1-m12;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-family: Courier New; font-size: 10pt;"&gt;cards&lt;/SPAN&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp; 0 1 4 0 0 0 0 0 0 0 0 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp; 1 0 0 0 0 0 0 0 0 0 0 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp; 0 0 0 0 0 0 0 0 5 0 6 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp; ;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;STRONG style="color: #000080; font-size: 10pt; font-family: Courier New;"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;BR /&gt; &lt;BR /&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;STRONG style="color: #000080; font-size: 10pt; font-family: Courier New;"&gt;data&lt;/STRONG&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt; two;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-family: Courier New; font-size: 10pt;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt; one;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; zero = sum(m1=&lt;/SPAN&gt;&lt;STRONG style="color: #008080; font-size: 10pt; font-family: Courier New;"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;,m2=&lt;/SPAN&gt;&lt;STRONG style="color: #008080; font-size: 10pt; font-family: Courier New;"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;,m3=&lt;/SPAN&gt;&lt;STRONG style="color: #008080; font-size: 10pt; font-family: Courier New;"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;,m4=&lt;/SPAN&gt;&lt;STRONG style="color: #008080; font-size: 10pt; font-family: Courier New;"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;,m5=&lt;/SPAN&gt;&lt;STRONG style="color: #008080; font-size: 10pt; font-family: Courier New;"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;,m6=&lt;/SPAN&gt;&lt;STRONG style="color: #008080; font-size: 10pt; font-family: Courier New;"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m7=&lt;/SPAN&gt;&lt;STRONG style="color: #008080; font-size: 10pt; font-family: Courier New;"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;,m8=&lt;/SPAN&gt;&lt;STRONG style="color: #008080; font-size: 10pt; font-family: Courier New;"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;,m9=&lt;/SPAN&gt;&lt;STRONG style="color: #008080; font-size: 10pt; font-family: Courier New;"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;,m10=&lt;/SPAN&gt;&lt;STRONG style="color: #008080; font-size: 10pt; font-family: Courier New;"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;,m11=&lt;/SPAN&gt;&lt;STRONG style="color: #008080; font-size: 10pt; font-family: Courier New;"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;,m12=&lt;/SPAN&gt;&lt;STRONG style="color: #008080; font-size: 10pt; font-family: Courier New;"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; nonzero = &lt;/SPAN&gt;&lt;STRONG style="color: #008080; font-size: 10pt; font-family: Courier New;"&gt;12&lt;/STRONG&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt; - zero;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-family: Courier New; font-size: 10pt;"&gt;put&lt;/SPAN&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt; nonzero=;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;STRONG style="color: #000080; font-size: 10pt; font-family: Courier New;"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-family: Courier New; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2011 20:51:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-or-array/m-p/12504#M1363</guid>
      <dc:creator>chang_y_chung_hotmail_com</dc:creator>
      <dc:date>2011-06-15T20:51:57Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop or array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-or-array/m-p/12505#M1364</link>
      <description>the idea of count() seems to be a bit of a failure, since the list of columns could as easily be adapted to fill the chang_y_chung solution,  as any other.&lt;BR /&gt;
for what it is worth,  I was seeking  &lt;BR /&gt;
 &lt;BR /&gt;
 given a macro variable &amp;amp;names holding the list of columns to be tested for 0&lt;BR /&gt;
 &lt;BR /&gt;
%let list_count = %sysfunc( countw( &amp;amp;names )) ;&lt;BR /&gt;
non_zeroes =  &amp;amp;list_count - count( '/'!! catx( '//', of &amp;amp;names ) !!'/', '/0/'  );&lt;BR /&gt;
 &lt;BR /&gt;
using catx() to convert the numerics in the list to character &lt;BR /&gt;
then counting the occurrence of '/0/'</description>
      <pubDate>Wed, 15 Jun 2011 23:10:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-or-array/m-p/12505#M1364</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-06-15T23:10:14Z</dc:date>
    </item>
  </channel>
</rss>

