<?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: Error in simple Sum in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Error-in-simple-Sum/m-p/894223#M353238</link>
    <description>&lt;P&gt;Please post the log as text, the data as working data step and the complete code of the step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 14 Sep 2023 07:14:02 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2023-09-14T07:14:02Z</dc:date>
    <item>
      <title>Error in simple Sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-in-simple-Sum/m-p/894221#M353236</link>
      <description>&lt;P&gt;I'm trying to calculate the sum of 3 columns. But when I use the summation, some of the records give me wrong result.&lt;/P&gt;&lt;P&gt;It's simple&lt;/P&gt;&lt;P&gt;Sum(0, colA, colB, colC)&lt;/P&gt;&lt;P&gt;ColA, ColB, ColC are blank. So the total should be 0. But I get 2.&lt;/P&gt;&lt;P&gt;Please help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Sep 2023 06:25:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-in-simple-Sum/m-p/894221#M353236</guid>
      <dc:creator>Azuki707</dc:creator>
      <dc:date>2023-09-14T06:25:11Z</dc:date>
    </item>
    <item>
      <title>Re: Error in simple Sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-in-simple-Sum/m-p/894223#M353238</link>
      <description>&lt;P&gt;Please post the log as text, the data as working data step and the complete code of the step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Sep 2023 07:14:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-in-simple-Sum/m-p/894223#M353238</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2023-09-14T07:14:02Z</dc:date>
    </item>
    <item>
      <title>Re: Error in simple Sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-in-simple-Sum/m-p/894225#M353240</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As well as showing your code and any messages from the log using the Insert Code icon "&amp;lt;/&amp;gt;" when posting, also confirm that the columns are numeric, as opposed to character, as you said they were blank, whereas the default representation&amp;nbsp;(which can be changed)&lt;SPAN&gt;&amp;nbsp;for a missing numeric value is "&lt;FONT face="courier new,courier"&gt;.&lt;/FONT&gt;".&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Try filtering the data to show any non-missing and non-zero values, e.g.:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  
  where colA or colB or colC;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks &amp;amp; kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Sep 2023 07:54:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-in-simple-Sum/m-p/894225#M353240</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2023-09-14T07:54:07Z</dc:date>
    </item>
    <item>
      <title>Re: Error in simple Sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-in-simple-Sum/m-p/894517#M353337</link>
      <description>&lt;P&gt;I don't understand why you say "&lt;SPAN&gt;ColA, ColB, ColC are blank." Do you mean missing values? A numeric variable cannot be "blank."&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Here are two examples that demonstrate how the DATA step works for numeric variables (hopefully this is your situation) and character variables (probably a mistake that should be fixed). In both cases, the total is 0 when the variables are all missing.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* the usual case: the variables are numeric */
data Have;
input colA colB colC;
sum = Sum(0, colA, colB, colC); /* variables are numeric */
datalines;
1 2 3
. 2 3
1 . 3
1 2 .
. . .
;

proc print data=Have; run;

/* How does the SUM function behave if given character 
   variables that can be converted to numbers? */
data Have2;
length colA colB colC $1;
infile DATALINES delimiter=',' DSD;
input colA colB colC $;    /* make variables character */
sum = Sum(0, colA, colB, colC);
datalines;
'1', '2', '3'
' ', '2', '3'
'1', ' ', '3'
'1', '2', ' '
' ', ' ', ' ' 
;

proc print data=Have2; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 15 Sep 2023 17:30:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-in-simple-Sum/m-p/894517#M353337</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2023-09-15T17:30:36Z</dc:date>
    </item>
  </channel>
</rss>

