<?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 The sum does not work? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/The-sum-does-not-work/m-p/852157#M336871</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I created a sum variable to calculate the sum of three columns; I found out that the function didn't work in the missing value.&amp;nbsp; Please help; thanks.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Cost;  
	Format IDs $10. ED DOLLAR15.2 ICU DOLLAR15.2 Lab DOLLAR15.2; 
	inFormat IDs $10. ED ICU Lab comma15.; 
	infile datalines delimiter='/'; 
	input IDs ED ICU Lab;  
	datalines;                     
EC1R00002/ 899.28/ / 256.31/
KC1Y00012/ / 11,080.82/ 619.91/
WC1G00013/ 332.34/ 929.71/ 2,066.98/
;  

data Cost_Sum;
	set Cost;
	sum=ED+ICU+Lab;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 04 Jan 2023 17:08:32 GMT</pubDate>
    <dc:creator>ybz12003</dc:creator>
    <dc:date>2023-01-04T17:08:32Z</dc:date>
    <item>
      <title>The sum does not work?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-sum-does-not-work/m-p/852157#M336871</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I created a sum variable to calculate the sum of three columns; I found out that the function didn't work in the missing value.&amp;nbsp; Please help; thanks.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Cost;  
	Format IDs $10. ED DOLLAR15.2 ICU DOLLAR15.2 Lab DOLLAR15.2; 
	inFormat IDs $10. ED ICU Lab comma15.; 
	infile datalines delimiter='/'; 
	input IDs ED ICU Lab;  
	datalines;                     
EC1R00002/ 899.28/ / 256.31/
KC1Y00012/ / 11,080.82/ 619.91/
WC1G00013/ 332.34/ 929.71/ 2,066.98/
;  

data Cost_Sum;
	set Cost;
	sum=ED+ICU+Lab;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2023 17:08:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-sum-does-not-work/m-p/852157#M336871</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2023-01-04T17:08:32Z</dc:date>
    </item>
    <item>
      <title>Re: The sum does not work?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-sum-does-not-work/m-p/852158#M336872</link>
      <description>&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068" target="_self"&gt;Maxim 2&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;READ THE LOG&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;1130  data Cost_Sum;
1131      set Cost;
1132      sum=ED+ICU+Lab;
1133  run;

NOTE: Missing values were generated as a result of performing an operation on missing values.
      Each place is given by: (Number of times) at (Line):(Column).
      2 at 1132:11
NOTE: There were 3 observations read from the data set WORK.COST.
NOTE: The data set WORK.COST_SUM has 3 observations and 5 variables.
NOTE: Compressing data set WORK.COST_SUM increased size by 100.00 percent.
      Compressed is 2 pages; un-compressed would require 1 pages.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can't add missing values to a non-missing. The result is a missing value. The solution is to use the SUM function, which ignores missing values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;sum=sum(ED,ICU,Lab);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2023 17:16:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-sum-does-not-work/m-p/852158#M336872</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-01-04T17:16:30Z</dc:date>
    </item>
    <item>
      <title>Re: The sum does not work?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-sum-does-not-work/m-p/852159#M336873</link>
      <description>Awesome, thanks.</description>
      <pubDate>Wed, 04 Jan 2023 17:17:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-sum-does-not-work/m-p/852159#M336873</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2023-01-04T17:17:48Z</dc:date>
    </item>
    <item>
      <title>Re: The sum does not work?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-sum-does-not-work/m-p/852187#M336886</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/67134"&gt;@ybz12003&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would add the ROUND function to &lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892" target="_blank" rel="noopener"&gt;PaigeMiller&lt;/A&gt;'s solution:&lt;/P&gt;
&lt;PRE&gt;sum=&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;round(&lt;/STRONG&gt;&lt;/FONT&gt;sum(ED,ICU,Lab)&lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;,0.01)&lt;/FONT&gt;&lt;/STRONG&gt;;&lt;/PRE&gt;
&lt;P&gt;(or with a suitable smaller rounding unit than 0.01 if any of the &lt;FONT face="courier new,courier"&gt;ED&lt;/FONT&gt;, &lt;FONT face="courier new,courier"&gt;ICU&lt;/FONT&gt; or &lt;FONT face="courier new,courier"&gt;Lab&lt;/FONT&gt; values could have more than two decimals).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The reason is that otherwise (!) tiny rounding errors are likely to occur, which can cause unwanted surprises later on. Your third example is a case in point. Using Windows SAS 9.4M5, the ROUND function makes a difference:&lt;/P&gt;
&lt;PRE&gt;data _null_;
input ED ICU Lab :comma.;
sum_old = sum(ED,ICU,Lab);
sum_new = round(sum(ED,ICU,Lab),0.01);
put (sum:) (= best32. /);
if sum_old ne sum_new then put / 'Surprised?' /;
put (sum:) (= hex16. /);
cards;
332.34 929.71 2,066.98
;

Log:
sum_old=3329.03
sum_new=3329.03

Surprised?

sum_old=40AA020F5C28F5C2
sum_new=40AA020F5C28F5C3&lt;/PRE&gt;
&lt;P&gt;Note that the HEX16. representation of &lt;FONT face="courier new,courier"&gt;sum_new&lt;/FONT&gt; is correctly rounded up: ...F5C&lt;STRONG&gt;2&lt;/STRONG&gt;&lt;FONT color="#999999"&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;8&lt;/FONT&gt;&lt;/STRONG&gt;F5C28F5C28&lt;/FONT&gt;...&amp;nbsp;→ ...F5C&lt;STRONG&gt;3&lt;/STRONG&gt; (repeating 5-digit pattern in a hexadecimal periodic fraction), whereas in &lt;FONT face="courier new,courier"&gt;sum_old&lt;/FONT&gt; it is rounded down, making it unequal to 3329.03.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2023 19:40:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-sum-does-not-work/m-p/852187#M336886</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2023-01-04T19:40:19Z</dc:date>
    </item>
  </channel>
</rss>

