<?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: &amp;quot;Sum if&amp;quot; - through an array in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/quot-Sum-if-quot-through-an-array/m-p/612694#M178818</link>
    <description>&lt;P&gt;I just eliminate the "else part" since it will do it anyway (doing nothing). Problem solved.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 18 Dec 2019 14:33:12 GMT</pubDate>
    <dc:creator>Krauss</dc:creator>
    <dc:date>2019-12-18T14:33:12Z</dc:date>
    <item>
      <title>"Sum if" - through an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quot-Sum-if-quot-through-an-array/m-p/612630#M178808</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could somebody help me to identify the error on this very simple piece of code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data HAVE;&lt;/P&gt;&lt;P&gt;set HAVE;&lt;BR /&gt;array columns {*} _numeric_;&lt;BR /&gt;SOMA=0;&lt;BR /&gt;CONTAGEM=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;do i = 1 to dim(columns);&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if abs(columns {i}) &amp;gt;0 then&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CONTAGEM= CONTAGEM+1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SOMA=SOMA+colunas {i};&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CONTAGEM=CONTAGEM&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SOMA=SOMA;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The gold is count (and sum) the number of variables of an array that the absolute value (abs) are greater than zero (for example).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This code returns this error and I can't interpret it:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"&lt;/P&gt;&lt;P&gt;SOMA=SOMA+colunas {i};&lt;BR /&gt;____&lt;BR /&gt;22&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, *, **, +, -, /, ;, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;&amp;lt;, &amp;gt;=, AND, EQ, GE, GT,&lt;BR /&gt;IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=, |, ||, ~=.&lt;/P&gt;&lt;P&gt;38 else&lt;BR /&gt;39 CONTAGEM=CONTAGEM&lt;BR /&gt;40 SOMA=SOMA;&lt;BR /&gt;____&lt;BR /&gt;22&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, (, *, **, +, -, /, ;, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;&amp;lt;, &amp;gt;=, AND, EQ, GE,&lt;BR /&gt;GT, IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, [, ^=, {, |, ||, ~=.&lt;/P&gt;&lt;P&gt;41 end;&lt;BR /&gt;42 end;&lt;BR /&gt;___&lt;BR /&gt;161&lt;BR /&gt;ERROR 161-185: No matching DO/SELECT statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Krauss&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2019 12:46:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quot-Sum-if-quot-through-an-array/m-p/612630#M178808</guid>
      <dc:creator>Krauss</dc:creator>
      <dc:date>2019-12-18T12:46:18Z</dc:date>
    </item>
    <item>
      <title>Re: "Sum if" - through an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quot-Sum-if-quot-through-an-array/m-p/612656#M178810</link>
      <description>&lt;P&gt;You are missing semi-colons at the end of your commands.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the future, please show us the entire log for your DATA step or PROC, not just the errors, by pasting (as text) the log into the window that appears when you click on the {i} icon. This will preserve the formatting of the log, and allow us to more easily identify where the problem is. Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2019 13:10:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quot-Sum-if-quot-through-an-array/m-p/612656#M178810</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-12-18T13:10:09Z</dc:date>
    </item>
    <item>
      <title>Re: "Sum if" - through an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quot-Sum-if-quot-through-an-array/m-p/612679#M178811</link>
      <description>&lt;PRE&gt;1                                                          The SAS System                           13:15 Tuesday, December 17, 2019

1          ;*';*";*/;quit;run;
2          OPTIONS PAGENO=MIN;
3          %LET _CLIENTTASKLABEL='Program';
4          %LET _CLIENTPROCESSFLOWNAME='Process Flow';
5          %LET _CLIENTPROJECTPATH='';
6          %LET _CLIENTPROJECTPATHHOST='';
7          %LET _CLIENTPROJECTNAME='';
8          %LET _SASPROGRAMFILE='';
9          %LET _SASPROGRAMFILEHOST='';
10         
11         ODS _ALL_ CLOSE;
12         OPTIONS DEV=PNG;
13         GOPTIONS XPIXELS=0 YPIXELS=0;
14         FILENAME EGSR TEMP;
15         ODS tagsets.sasreport13(ID=EGSR) FILE=EGSR
16             STYLE=HtmlBlue
17             STYLESHEET=(URL="file:///C:/Applics/SASHome/x86/SASEnterpriseGuide/7.1/Styles/HtmlBlue.css")
18             NOGTITLE
19             NOGFOOTNOTE
20             GPATH=&amp;amp;sasworklocation
21             ENCODING=UTF8
22             options(rolap="on")
23         ;
NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR
24         
25         GOPTIONS ACCESSIBLE;
26         data work.step1;
27         
28         set work.step1;
29         	array colunas {*} _numeric_;
30          SOMA=0;
31          CONTAGEM=0;
32         
33         do i = 1 to dim(colunas);
34         
35          	if abs(colunas {i}) &amp;gt;0 then
36         		CONTAGEM= CONTAGEM+1
37         		SOMA=SOMA+colunas {i};
             ____
             22
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, *, **, +, -, /, ;, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;&amp;lt;, &amp;gt;=, AND, EQ, GE, GT, 
              IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=, |, ||, ~=.  

38         	else
39         		CONTAGEM=CONTAGEM
40         		SOMA=SOMA;
             ____
             22
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, (, *, **, +, -, /, ;, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;&amp;lt;, &amp;gt;=, AND, EQ, GE, 
              GT, IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, [, ^=, {, |, ||, ~=.  

41         	end;
42         end;
           ___
           161
ERROR 161-185: No matching DO/SELECT statement.

43         
2                                                          The SAS System                           13:15 Tuesday, December 17, 2019

44         run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.STEP1 may be incomplete.  When this step was stopped there were 0 observations and 467 variables.
WARNING: Data set WORK.STEP1 was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      user cpu time       0.00 seconds
      system cpu time     0.01 seconds
      memory              1605.21k
      OS Memory           27316.00k
      Timestamp           12/18/2019 12:21:47 PM
      Step Count                        45  Switch Count  0
      Page Faults                       2
      Page Reclaims                     215
      Page Swaps                        0
      Voluntary Context Switches        11
      Involuntary Context Switches      0
      Block Input Operations            1024
      Block Output Operations           8
      

45         
46         GOPTIONS NOACCESSIBLE;
47         %LET _CLIENTTASKLABEL=;
48         %LET _CLIENTPROCESSFLOWNAME=;
49         %LET _CLIENTPROJECTPATH=;
50         %LET _CLIENTPROJECTPATHHOST=;
51         %LET _CLIENTPROJECTNAME=;
52         %LET _SASPROGRAMFILE=;
53         %LET _SASPROGRAMFILEHOST=;
54         
55         ;*';*";*/;quit;run;
56         ODS _ALL_ CLOSE;
57         
58         
59         QUIT; RUN;
60         &lt;/PRE&gt;&lt;P&gt;Where the log indicates the error I have semi-colons already. How should I know where they are missing?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thks!&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2019 13:19:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quot-Sum-if-quot-through-an-array/m-p/612679#M178811</guid>
      <dc:creator>Krauss</dc:creator>
      <dc:date>2019-12-18T13:19:55Z</dc:date>
    </item>
    <item>
      <title>Re: "Sum if" - through an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quot-Sum-if-quot-through-an-array/m-p/612680#M178812</link>
      <description>&lt;P&gt;Each command must end with a semi-colon. Look carefully, there are commands with no semi-colons at the end.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2019 13:24:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quot-Sum-if-quot-through-an-array/m-p/612680#M178812</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-12-18T13:24:41Z</dc:date>
    </item>
    <item>
      <title>Re: "Sum if" - through an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quot-Sum-if-quot-through-an-array/m-p/612683#M178815</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/303353"&gt;@Krauss&lt;/a&gt;&amp;nbsp; did you notice the missing DO and END blocks? I think the following correction is what is required&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
          if abs(columns {i}) &amp;gt;0 then do;
             CONTAGEM= CONTAGEM+1;
             SOMA=SOMA+colunas {i};
			 end;
          else do;
            CONTAGEM=CONTAGEM;
            SOMA=SOMA;
         end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Dec 2019 13:42:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quot-Sum-if-quot-through-an-array/m-p/612683#M178815</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-12-18T13:42:06Z</dc:date>
    </item>
    <item>
      <title>Re: "Sum if" - through an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quot-Sum-if-quot-through-an-array/m-p/612694#M178818</link>
      <description>&lt;P&gt;I just eliminate the "else part" since it will do it anyway (doing nothing). Problem solved.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2019 14:33:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quot-Sum-if-quot-through-an-array/m-p/612694#M178818</guid>
      <dc:creator>Krauss</dc:creator>
      <dc:date>2019-12-18T14:33:12Z</dc:date>
    </item>
    <item>
      <title>Re: "Sum if" - through an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quot-Sum-if-quot-through-an-array/m-p/612696#M178820</link>
      <description>&lt;P&gt;Not exactly solved.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The sums are wrong whenever there is a negative number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would suggest paying attention to the suggestion about adding DO and END.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2019 14:43:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quot-Sum-if-quot-through-an-array/m-p/612696#M178820</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-12-18T14:43:33Z</dc:date>
    </item>
    <item>
      <title>Re: "Sum if" - through an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quot-Sum-if-quot-through-an-array/m-p/612721#M178835</link>
      <description>&lt;PRE&gt;data HAVE; /* BAD idea to replace your source data set until you KNOW your
                    code is working correctly*/

set HAVE;
array columns {*} _numeric_;
SOMA=0;
CONTAGEM=0;

       do i = 1 to dim(columns);

          if abs(columns {i}) &amp;gt;0 then&lt;FONT color="#ff0000"&gt;&lt;STRONG&gt; DO;&lt;/STRONG&gt;&lt;/FONT&gt;
             CONTAGEM= CONTAGEM+1&lt;FONT color="#ff0000"&gt;&lt;STRONG&gt;;
&lt;/STRONG&gt;&lt;/FONT&gt;             SOMA=SOMA+colunas {i};&lt;BR /&gt;          &lt;FONT color="#ff0000"&gt;&lt;STRONG&gt;end;&lt;/STRONG&gt;&lt;/FONT&gt;
          else &lt;FONT color="#ff0000"&gt;&lt;STRONG&gt;do;&lt;/STRONG&gt;&lt;/FONT&gt;
            CONTAGEM=CONTAGEM&lt;FONT color="#ff0000"&gt;&lt;STRONG&gt; ;
&lt;/STRONG&gt;&lt;/FONT&gt;            SOMA=SOMA;
         end;
     end;

run;
&lt;/PRE&gt;
&lt;P&gt;EVERY SAS statement needs a ; to end the statement. So when you use&lt;/P&gt;
&lt;PRE&gt; CONTAGEM= CONTAGEM+1
 SOMA=SOMA+colunas {i};&lt;/PRE&gt;
&lt;P&gt;The first statement Contagem = Contagem +1 is &lt;STRONG&gt;not ended&lt;/STRONG&gt; when the compiler encounters SOMA. Since the previous statement involves numeric computation then the compiler expects something related to SOMA in how it is used in the &lt;STRONG&gt;previous&lt;/STRONG&gt; computation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second. If you need multiple statements evaluated as part of an IF /Then /Else then you a DO /END block to tell SAS which multiple statements are conditional.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW:&lt;/P&gt;
&lt;PRE&gt;          else
            CONTAGEM=CONTAGEM
            SOMA=SOMA;
         end;&lt;/PRE&gt;
&lt;P&gt;is basically a complete waste of electrons. Since you are not changing the values then why bother?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2019 15:53:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quot-Sum-if-quot-through-an-array/m-p/612721#M178835</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-12-18T15:53:53Z</dc:date>
    </item>
  </channel>
</rss>

