<?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 loops and Array processing in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/DO-loops-and-Array-processing/m-p/42236#M8674</link>
    <description>Hello KDang,&lt;BR /&gt;
&lt;BR /&gt;
The Initialization step has been included to create initial data for your input arrays a1q, etc. It is not necessary in your program.&lt;BR /&gt;
&lt;BR /&gt;
Sincerely,&lt;BR /&gt;
SPR</description>
    <pubDate>Wed, 01 Dec 2010 17:40:57 GMT</pubDate>
    <dc:creator>SPR</dc:creator>
    <dc:date>2010-12-01T17:40:57Z</dc:date>
    <item>
      <title>DO loops and Array processing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-loops-and-Array-processing/m-p/42231#M8669</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I have values for the following variables that are either  0 or 1 :&lt;BR /&gt;
q1a_1 - q1a_14 &lt;BR /&gt;
q1b_1 - q1b_14&lt;BR /&gt;
q1c_1 - q1c_14&lt;BR /&gt;
q1d_1 - q1d_14&lt;BR /&gt;
&lt;BR /&gt;
There are a few new variables I want to create:&lt;BR /&gt;
&lt;BR /&gt;
q1before_1 - q1before_14: for each iteration 1 - 14, this variable will check if q1a_{i} OR q1c_{i} contains a 1 (or sum of GE 1), if GE 1 then q1before_{i} = 1 .&lt;BR /&gt;
&lt;BR /&gt;
q1after_1 - q1after_14:  for each iteration 1 - 14, this variable will check if q1b_{i} OR q1d_{i} contains a 1 (or sum of GE 1), if GE 1 then q1after_{i} = 1 .&lt;BR /&gt;
&lt;BR /&gt;
I can write out each iteration, but I'm looking for a solution (if possible) that will condense my code with DO loops and arrays (or other solutions).&lt;BR /&gt;
&lt;BR /&gt;
Thanks for your help!</description>
      <pubDate>Wed, 01 Dec 2010 14:31:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-loops-and-Array-processing/m-p/42231#M8669</guid>
      <dc:creator>KDang</dc:creator>
      <dc:date>2010-12-01T14:31:25Z</dc:date>
    </item>
    <item>
      <title>Re: DO loops and Array processing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-loops-and-Array-processing/m-p/42232#M8670</link>
      <description>Hello KDang,&lt;BR /&gt;
&lt;BR /&gt;
Is this the code are you looking for?&lt;BR /&gt;
[pre]&lt;BR /&gt;
data a;&lt;BR /&gt;
  array q1a {14} q1a_1-q1a_14;&lt;BR /&gt;
  array q1b {14} q1b_1-q1b_14;&lt;BR /&gt;
  array q1c {14} q1c_1-q1c_14;&lt;BR /&gt;
  array q1d {14} q1d_1-q1d_14;&lt;BR /&gt;
  array q1before {14} q1before_1-q1before_14;&lt;BR /&gt;
  array q1after {14} q1after_1- q1after_14;&lt;BR /&gt;
  /* Array Initialization */;&lt;BR /&gt;
  do i=1 to 14;&lt;BR /&gt;
    q1a[i]=RAND('BERNOULLI',0.1);&lt;BR /&gt;
    q1b[i]=RAND('BERNOULLI',0.2);&lt;BR /&gt;
    q1c[i]=RAND('BERNOULLI',0.3);&lt;BR /&gt;
    q1d[i]=RAND('BERNOULLI',0.4);&lt;BR /&gt;
  end;&lt;BR /&gt;
  /* Calculation */;&lt;BR /&gt;
  do i=1 to 14;&lt;BR /&gt;
    if q1a[i]+q1c[i] GE 1 then q1before[i]=1;&lt;BR /&gt;
    if q1b[i]+q1d[i] GE 1 then q1after[i]=1;&lt;BR /&gt;
  end;&lt;BR /&gt;
  drop i;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Sincerely,&lt;BR /&gt;
SPR</description>
      <pubDate>Wed, 01 Dec 2010 14:57:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-loops-and-Array-processing/m-p/42232#M8670</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2010-12-01T14:57:30Z</dc:date>
    </item>
    <item>
      <title>Re: DO loops and Array processing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-loops-and-Array-processing/m-p/42233#M8671</link>
      <description>&amp;gt; q1before_1 - q1before_14: for each iteration 1 - 14,&lt;BR /&gt;
&amp;gt; this variable will check if q1a_{i} OR q1c_{i}&lt;BR /&gt;
&amp;gt; contains a 1 (or sum of GE 1), if GE 1 then&lt;BR /&gt;
&amp;gt; q1before_{i} = 1 .&lt;BR /&gt;
&lt;BR /&gt;
BEFORE = (ASET or CSET);&lt;BR /&gt;
 &lt;BR /&gt;
&amp;gt; q1after_1 - q1after_14:  for each iteration 1 - 14,&lt;BR /&gt;
&amp;gt; this variable will check if q1b_{i} OR q1d_{i}&lt;BR /&gt;
&amp;gt; contains a 1 (or sum of GE 1), if GE 1 then&lt;BR /&gt;
&amp;gt; q1after_{i} = 1 .&lt;BR /&gt;
&lt;BR /&gt;
AFTER  = ( BSET or DSET);&lt;BR /&gt;
&lt;BR /&gt;
the SAS code could be as simple if you use the (less-well-documented) array style called IMPLICIT arrays[pre]&lt;BR /&gt;
array aset q1a_1 - q1a_14 ; &lt;BR /&gt;
array bset q1b_1 - q1b_14 ;&lt;BR /&gt;
array cset q1c_1 - q1c_14 ;&lt;BR /&gt;
array dset q1d_1 - q1d_14 ;&lt;BR /&gt;
array before q1before_1 - q1before_14 ;&lt;BR /&gt;
array after  q1after_1 - q1after_14 ;&lt;BR /&gt;
 &lt;BR /&gt;
do over before ;&lt;BR /&gt;
 AFTER  = (BSET or DSET);&lt;BR /&gt;
 BEFORE = (ASET or CSET);&lt;BR /&gt;
end ;[/pre]&lt;BR /&gt;
For those who prefer nothing remotely undocumented or like to see more syntax, I reccommend the exercise of providing the demonstration..&lt;BR /&gt;
;-)&lt;BR /&gt;
peterC</description>
      <pubDate>Wed, 01 Dec 2010 15:14:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-loops-and-Array-processing/m-p/42233#M8671</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2010-12-01T15:14:31Z</dc:date>
    </item>
    <item>
      <title>Re: DO loops and Array processing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-loops-and-Array-processing/m-p/42234#M8672</link>
      <description>Yes thank you SPR, it worked perfectly.&lt;BR /&gt;
&lt;BR /&gt;
Although, I didnt include the array initialization step, just because I dont really understand it..&lt;BR /&gt;
i'm just curious what it does?</description>
      <pubDate>Wed, 01 Dec 2010 15:22:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-loops-and-Array-processing/m-p/42234#M8672</guid>
      <dc:creator>KDang</dc:creator>
      <dc:date>2010-12-01T15:22:13Z</dc:date>
    </item>
    <item>
      <title>Re: DO loops and Array processing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-loops-and-Array-processing/m-p/42235#M8673</link>
      <description>Thanks PeterC that worked perfectly as well, really simple and easy to understand.</description>
      <pubDate>Wed, 01 Dec 2010 15:32:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-loops-and-Array-processing/m-p/42235#M8673</guid>
      <dc:creator>KDang</dc:creator>
      <dc:date>2010-12-01T15:32:52Z</dc:date>
    </item>
    <item>
      <title>Re: DO loops and Array processing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-loops-and-Array-processing/m-p/42236#M8674</link>
      <description>Hello KDang,&lt;BR /&gt;
&lt;BR /&gt;
The Initialization step has been included to create initial data for your input arrays a1q, etc. It is not necessary in your program.&lt;BR /&gt;
&lt;BR /&gt;
Sincerely,&lt;BR /&gt;
SPR</description>
      <pubDate>Wed, 01 Dec 2010 17:40:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-loops-and-Array-processing/m-p/42236#M8674</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2010-12-01T17:40:57Z</dc:date>
    </item>
  </channel>
</rss>

