<?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: Counting array with prefix in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Counting-array-with-prefix/m-p/267242#M52791</link>
    <description>&lt;P&gt;Oh, I didn't see the 100's of variables. &amp;nbsp;I agree totally, why have hundreds of variables. &amp;nbsp;Doesn't make any sense. &amp;nbsp;Any processing you do on that type of strcuture is going to be far harder. &amp;nbsp;Normalise your data, process it using a simple structure, then at teh end transpose it. &amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 29 Apr 2016 14:27:28 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2016-04-29T14:27:28Z</dc:date>
    <item>
      <title>Counting array with prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-array-with-prefix/m-p/267228#M52787</link>
      <description>&lt;P&gt;I have the following data file&lt;/P&gt;
&lt;P&gt;For each variable a, b, c I have 3 period (p1 p2 p3) reporting the value.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data have;&lt;BR /&gt;input time &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;p1a p2a p3a &amp;nbsp; &amp;nbsp; &amp;nbsp; p1b p2b p3b &amp;nbsp; &amp;nbsp; &amp;nbsp;p1c p2c p3c;&lt;BR /&gt;datalines;&lt;BR /&gt;1 1 0 -1 6 9 5 3 -9 6&lt;BR /&gt;2 2 3 6 0 0 0 -2 -2 -9&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;for each row, I want to count the number of positive period for A, B, C seperately.&lt;BR /&gt;The summary column for a , b, c is: &lt;BR /&gt;1 3 2 &lt;BR /&gt;3 0 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In my data, there are 100 of variables, so I cannot array 1 by 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for your help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;</description>
      <pubDate>Fri, 29 Apr 2016 13:59:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-array-with-prefix/m-p/267228#M52787</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2016-04-29T13:59:13Z</dc:date>
    </item>
    <item>
      <title>Re: Counting array with prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-array-with-prefix/m-p/267233#M52789</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't have access to SAS at the moment, but something like:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  array dat{9} p1a--p3c;
  array res{9} 1;
  do i=1 to 9;
    if dat{i} &amp;gt; 0 then res{i}=1;
  end;
  a=sum(res1-res3);
  b=sum(res4-res6);
  c=sum(res7-res9);
run;&lt;/PRE&gt;
&lt;P&gt;or:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  a=sum(ifn(p1a&amp;gt;0,1,0),ifn(p2a&amp;gt;0,1,0),ifn(p3a&amp;gt;0,1,0));
  b=sum(ifn(p1b&amp;gt;0,1,0),ifn(p2b&amp;gt;0,1,0),ifn(p3b&amp;gt;0,1,0));
  c=sum(ifn(p1c&amp;gt;0,1,0),ifn(p2c&amp;gt;0,1,0),ifn(p3c&amp;gt;0,1,0));
run;
&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Apr 2016 14:11:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-array-with-prefix/m-p/267233#M52789</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-04-29T14:11:12Z</dc:date>
    </item>
    <item>
      <title>Re: Counting array with prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-array-with-prefix/m-p/267239#M52790</link>
      <description>&lt;P&gt;I would question the decision to name the variables p1a p2a and p3a if I knew that I was going to process them as a group. Names of ap1 ap2 and ap3 would then work better. You may need to provide more examples of the "100 of variables" involved as a solution&amp;nbsp;for your example may not&amp;nbsp;work with longer or variable length names or suffixes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One approach is to create variables with the suffix as a prefix so that arrays are possible. This will do that but if the actual variables have varying length names and suffixes it will not work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input time        p1a p2a p3a       p1b p2b p3b      p1c p2c p3c;
datalines;
1 1 0 -1 6 9 5 3 -9 6
2 2 3 6 0 0 0 -2 -2 -9
;

run;

proc transpose data=have out=trans;

run;

data temp;
   set trans;
   if _name_ ne 'time' then  _name_ = cats(substr(_name_,3),_name_);
run; 

proc transpose data=temp name=_name_ out=havetrans (drop=_name_);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;One suspects that a dataset with "hundreds" of similarly named variables may be the wrong structure in general and would be better served with&amp;nbsp; a Time Group (values of A B C in your example)&amp;nbsp;P1 P2 P3 structure in general.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Apr 2016 14:22:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-array-with-prefix/m-p/267239#M52790</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-04-29T14:22:02Z</dc:date>
    </item>
    <item>
      <title>Re: Counting array with prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-array-with-prefix/m-p/267242#M52791</link>
      <description>&lt;P&gt;Oh, I didn't see the 100's of variables. &amp;nbsp;I agree totally, why have hundreds of variables. &amp;nbsp;Doesn't make any sense. &amp;nbsp;Any processing you do on that type of strcuture is going to be far harder. &amp;nbsp;Normalise your data, process it using a simple structure, then at teh end transpose it. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Apr 2016 14:27:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-array-with-prefix/m-p/267242#M52791</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-04-29T14:27:28Z</dc:date>
    </item>
    <item>
      <title>Re: Counting array with prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-array-with-prefix/m-p/267248#M52794</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/49486"&gt;@hhchenfx﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How about this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=have out=trans;
by time;
run;

data trans;
do _n_=1 to 3;
  set trans;
  _name_=substr(_name_,3);
  npos=sum(npos,col1&amp;gt;0);
end;
drop col1;
run;

proc transpose data=trans out=want(drop=_name_);
by time;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Edit: Slightly simplified the DOW loop by using an iterative DO statement rather than a DO UNTIL statement and a counter variable.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Apr 2016 15:39:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-array-with-prefix/m-p/267248#M52794</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-04-29T15:39:58Z</dc:date>
    </item>
    <item>
      <title>Re: Counting array with prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-array-with-prefix/m-p/267255#M52799</link>
      <description>&lt;P&gt;Using arrays, the key to making this a short program is whether you can abbreviate the list of variables in the array. &amp;nbsp;For example, would this ARRAY statement define all 78 variables in the proper order?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;array all {78} p1a -- p3z;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so, the task becomes&amp;nbsp;straightforward:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;array all {78} p1a -- p3z;&lt;/P&gt;
&lt;P&gt;array sums {26} sum1-sum26;&lt;/P&gt;
&lt;P&gt;do _n_=1 to 26;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;sums{_n_}=0;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;do _n_=1 to 78;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if all{_n_} &amp;gt; 0 then sums{ceil(_n_/3)} + 1;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Apr 2016 14:56:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-array-with-prefix/m-p/267255#M52799</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-04-29T14:56:43Z</dc:date>
    </item>
  </channel>
</rss>

