<?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 Array to replace if then statement 9.4 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Array-to-replace-if-then-statement-9-4/m-p/446578#M112062</link>
    <description>&lt;P&gt;Need to create an array with a comparison that enables a&amp;nbsp;cumulative count after importing a text file , can get there with if then and sum statement but am stuck trying to create an array to do same.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;DATA&lt;/STRONG&gt; Answers;&lt;/P&gt;&lt;P&gt;infile grades;&lt;/P&gt;&lt;P&gt;input id $ score1 score2 score3 score4 score5;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if score1 &amp;gt; &lt;STRONG&gt;64&lt;/STRONG&gt; then Pass1 = &lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if score2 &amp;gt; &lt;STRONG&gt;64&lt;/STRONG&gt; then Pass2 = &lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if score3 &amp;gt; &lt;STRONG&gt;64&lt;/STRONG&gt; then Pass3 = &lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if score4 &amp;gt; &lt;STRONG&gt;64&lt;/STRONG&gt; then Pass4 = &lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if score5 &amp;gt; &lt;STRONG&gt;64&lt;/STRONG&gt; then Pass5 = &lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Passed = Sum(of Pass1-Pass5);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; drop Pass1 - Pass5;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt; &lt;STRONG&gt;PRINT&lt;/STRONG&gt; NOOBS;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;;&lt;/P&gt;</description>
    <pubDate>Sun, 18 Mar 2018 16:01:11 GMT</pubDate>
    <dc:creator>RickyS</dc:creator>
    <dc:date>2018-03-18T16:01:11Z</dc:date>
    <item>
      <title>Array to replace if then statement 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-to-replace-if-then-statement-9-4/m-p/446578#M112062</link>
      <description>&lt;P&gt;Need to create an array with a comparison that enables a&amp;nbsp;cumulative count after importing a text file , can get there with if then and sum statement but am stuck trying to create an array to do same.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;DATA&lt;/STRONG&gt; Answers;&lt;/P&gt;&lt;P&gt;infile grades;&lt;/P&gt;&lt;P&gt;input id $ score1 score2 score3 score4 score5;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if score1 &amp;gt; &lt;STRONG&gt;64&lt;/STRONG&gt; then Pass1 = &lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if score2 &amp;gt; &lt;STRONG&gt;64&lt;/STRONG&gt; then Pass2 = &lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if score3 &amp;gt; &lt;STRONG&gt;64&lt;/STRONG&gt; then Pass3 = &lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if score4 &amp;gt; &lt;STRONG&gt;64&lt;/STRONG&gt; then Pass4 = &lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if score5 &amp;gt; &lt;STRONG&gt;64&lt;/STRONG&gt; then Pass5 = &lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Passed = Sum(of Pass1-Pass5);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; drop Pass1 - Pass5;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt; &lt;STRONG&gt;PRINT&lt;/STRONG&gt; NOOBS;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;;&lt;/P&gt;</description>
      <pubDate>Sun, 18 Mar 2018 16:01:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-to-replace-if-then-statement-9-4/m-p/446578#M112062</guid>
      <dc:creator>RickyS</dc:creator>
      <dc:date>2018-03-18T16:01:11Z</dc:date>
    </item>
    <item>
      <title>Re: Array to replace if then statement 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-to-replace-if-then-statement-9-4/m-p/446580#M112063</link>
      <description>&lt;P&gt;I think this is what you are after:&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 scores {5} score1-score5;&lt;/P&gt;
&lt;P&gt;passed = 0;&lt;/P&gt;
&lt;P&gt;do k=1 to 5;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if scores{k} &amp;gt; 64 then passed + 1;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;drop k;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Sun, 18 Mar 2018 16:08:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-to-replace-if-then-statement-9-4/m-p/446580#M112063</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-03-18T16:08:28Z</dc:date>
    </item>
    <item>
      <title>Re: Array to replace if then statement 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-to-replace-if-then-statement-9-4/m-p/446581#M112064</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data answers;
    infile grades;
    input id $ score1 score2 score3 score4 score5;
    array score score1-score5;
    array pass pass1-pass5;
    do i = 1 to dim(score);
        if score(i)&amp;gt;65 then pass(i)=1;
    end;&lt;BR /&gt;    passed=sum(pass1-pass5);&lt;BR /&gt;run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;etc.&lt;/P&gt;</description>
      <pubDate>Sun, 18 Mar 2018 16:09:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-to-replace-if-then-statement-9-4/m-p/446581#M112064</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-03-18T16:09:35Z</dc:date>
    </item>
    <item>
      <title>Re: Array to replace if then statement 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-to-replace-if-then-statement-9-4/m-p/446585#M112066</link>
      <description>&lt;P&gt;You already have a couple of answers, but heres a slightly different way:&lt;/P&gt;
&lt;PRE&gt;data Answers;
  infile cards;
  input id $ score1-score5;
  array scores score1-score5;
  do over scores;
    Passed=sum(Passed,scores gt 64);
  end;
  cards;
0 1 1 1 1 1
1 1 70 1 1 1
2 90 2 2 2 88
3 3 65 3 66 67
;

&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 18 Mar 2018 16:14:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-to-replace-if-then-statement-9-4/m-p/446585#M112066</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-03-18T16:14:45Z</dc:date>
    </item>
    <item>
      <title>Re: Array to replace if then statement 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-to-replace-if-then-statement-9-4/m-p/446587#M112068</link>
      <description>&lt;P&gt;TY for the quick responses everyone&lt;/P&gt;</description>
      <pubDate>Sun, 18 Mar 2018 16:16:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-to-replace-if-then-statement-9-4/m-p/446587#M112068</guid>
      <dc:creator>RickyS</dc:creator>
      <dc:date>2018-03-18T16:16:49Z</dc:date>
    </item>
    <item>
      <title>Re: Array to replace if then statement 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-to-replace-if-then-statement-9-4/m-p/446589#M112069</link>
      <description>&lt;P&gt;all of the solutions work curious as to which is most efficient if anyone knows&lt;/P&gt;</description>
      <pubDate>Sun, 18 Mar 2018 16:32:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-to-replace-if-then-statement-9-4/m-p/446589#M112069</guid>
      <dc:creator>RickyS</dc:creator>
      <dc:date>2018-03-18T16:32:09Z</dc:date>
    </item>
    <item>
      <title>Re: Array to replace if then statement 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-to-replace-if-then-statement-9-4/m-p/446591#M112070</link>
      <description>&lt;P&gt;found some posts with &lt;STRONG&gt;do over&lt;/STRONG&gt; no longer supported in 9.4 but liked by many&lt;/P&gt;</description>
      <pubDate>Sun, 18 Mar 2018 16:37:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-to-replace-if-then-statement-9-4/m-p/446591#M112070</guid>
      <dc:creator>RickyS</dc:creator>
      <dc:date>2018-03-18T16:37:40Z</dc:date>
    </item>
    <item>
      <title>Re: Array to replace if then statement 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-to-replace-if-then-statement-9-4/m-p/446592#M112071</link>
      <description>&lt;P&gt;That can't possibly be that all of the solutions work.&amp;nbsp; They don't all produce the same result so at least one of them must be wrong.&amp;nbsp; I would suggest you test them on a few dozen observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Most likely, efficiency means choosing the solution that you are most comfortable with, the one that you could modify and adapt as needed.&amp;nbsp; Unless you are dealing with millions of observations, it is unlikely you could measure a difference in speed.&lt;/P&gt;</description>
      <pubDate>Sun, 18 Mar 2018 18:41:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-to-replace-if-then-statement-9-4/m-p/446592#M112071</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-03-18T18:41:40Z</dc:date>
    </item>
    <item>
      <title>Re: Array to replace if then statement 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-to-replace-if-then-statement-9-4/m-p/446659#M112111</link>
      <description>&lt;P&gt;I don't think "do over" has ever been documented, but I've always found it to be convenient. However, it's major problem is that (since it's not documented), is that it may not be available in future releases.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As for&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;'s comment about all of the proposed solutions can't be correct .. I agree! The one you selected as the solution doesn't provide the correct answer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As for which method is fastest, I also agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;. I tested the various solutions on a 2 million record file: (1) "do over" was slightly slower than a regular do loop and (2) using do i= 1 to dim(arrayname) was slightly slower than using do i= 1 to 5. However, even on a 2 million record file, the cpu times only ranged between around .18 seconds and .22 seconds.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The fastest method was:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  Passed=0;
  Passed+(score1 gt 64);
  Passed+(score2 gt 64);
  Passed+(score3 gt 64);
  Passed+(score4 gt 64);
  Passed+(score5 gt 64);
run;
&lt;/PRE&gt;
&lt;P&gt;It ran twice as fast as any of the methods but, of course, required more time to type.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 01:22:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-to-replace-if-then-statement-9-4/m-p/446659#M112111</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-03-19T01:22:45Z</dc:date>
    </item>
    <item>
      <title>Re: Array to replace if then statement 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-to-replace-if-then-statement-9-4/m-p/446799#M112167</link>
      <description>&lt;P&gt;&lt;STRONG&gt;DATA&lt;/STRONG&gt; Answers;&lt;/P&gt;&lt;P&gt;&amp;nbsp; infile grades;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input id $ score1 score2 score3 score4 score5;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; array score score1-score5;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array pass pass1-pass5;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do i = &lt;STRONG&gt;1&lt;/STRONG&gt; to dim(score);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if score(i) &amp;gt; &lt;STRONG&gt;65&lt;/STRONG&gt; then Pass(i) = &lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Passed = Sum(of Pass1-Pass5);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; drop i Pass1 - Pass5;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;RUN&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt; &lt;STRONG&gt;PRINT&lt;/STRONG&gt; NOOBS;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 14:36:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-to-replace-if-then-statement-9-4/m-p/446799#M112167</guid>
      <dc:creator>RickyS</dc:creator>
      <dc:date>2018-03-19T14:36:28Z</dc:date>
    </item>
    <item>
      <title>Re: Array to replace if then statement 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-to-replace-if-then-statement-9-4/m-p/446815#M112175</link>
      <description>&lt;P&gt;That covers one of the issues, adding the word "of".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Next, try using some scores that are exactly 65.&amp;nbsp; That's the last issue that I noticed.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 14:57:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-to-replace-if-then-statement-9-4/m-p/446815#M112175</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-03-19T14:57:17Z</dc:date>
    </item>
  </channel>
</rss>

