<?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 Unknown Subtraction Issue in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Unknown-Subtraction-Issue/m-p/711275#M219084</link>
    <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Running into an issue and I'm not sure what I'm missing here. I have 8 numeric variables, that I sum together, and then subtract a 9th numeric variable from the summation. When I simply sum the first 8 I get a valid output, however, when I try subtracting the 9th I get a period (.) There are some instances of missing values in all 9 columns, that's why I thought sum() was the best approach.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example code below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;DATA WORK.WANT;
SET WORK.HAVE;
TotalCount1 = sum(of Total1 -- Total8);
TotalCount = sum(TotalCount1 -Total9);
DROP TotalCount1;
RUN;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd prefer, this step below, but neither have worked&lt;/P&gt;
&lt;PRE&gt;DATA WORK.WANT;
SET WORK.HAVE;
TotalCount = sum(sum(Total1 -- Total8) - Total9);
RUN;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 13 Jan 2021 20:42:14 GMT</pubDate>
    <dc:creator>BlayLay</dc:creator>
    <dc:date>2021-01-13T20:42:14Z</dc:date>
    <item>
      <title>Unknown Subtraction Issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unknown-Subtraction-Issue/m-p/711275#M219084</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Running into an issue and I'm not sure what I'm missing here. I have 8 numeric variables, that I sum together, and then subtract a 9th numeric variable from the summation. When I simply sum the first 8 I get a valid output, however, when I try subtracting the 9th I get a period (.) There are some instances of missing values in all 9 columns, that's why I thought sum() was the best approach.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example code below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;DATA WORK.WANT;
SET WORK.HAVE;
TotalCount1 = sum(of Total1 -- Total8);
TotalCount = sum(TotalCount1 -Total9);
DROP TotalCount1;
RUN;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd prefer, this step below, but neither have worked&lt;/P&gt;
&lt;PRE&gt;DATA WORK.WANT;
SET WORK.HAVE;
TotalCount = sum(sum(Total1 -- Total8) - Total9);
RUN;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jan 2021 20:42:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unknown-Subtraction-Issue/m-p/711275#M219084</guid>
      <dc:creator>BlayLay</dc:creator>
      <dc:date>2021-01-13T20:42:14Z</dc:date>
    </item>
    <item>
      <title>Re: Unknown Subtraction Issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unknown-Subtraction-Issue/m-p/711277#M219086</link>
      <description>&lt;P&gt;Try&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;TotalCount = sum(of Total1 -- Total8) - Total9;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jan 2021 20:46:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unknown-Subtraction-Issue/m-p/711277#M219086</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-01-13T20:46:39Z</dc:date>
    </item>
    <item>
      <title>Re: Unknown Subtraction Issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unknown-Subtraction-Issue/m-p/711280#M219088</link>
      <description>No luck...still missing values as output</description>
      <pubDate>Wed, 13 Jan 2021 20:51:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unknown-Subtraction-Issue/m-p/711280#M219088</guid>
      <dc:creator>BlayLay</dc:creator>
      <dc:date>2021-01-13T20:51:37Z</dc:date>
    </item>
    <item>
      <title>Re: Unknown Subtraction Issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unknown-Subtraction-Issue/m-p/711291#M219093</link>
      <description>&lt;P&gt;By using - instead of comma in the SUM() function call you are summing only one value, the result of the normal subtraction.&amp;nbsp; So you are defeating the purpose of using the SUM() function.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;TotalCount = sum(of total1-total8, -total9);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to avoid the NOTE in the log about missing values you will still have to check if TOTAL9 is missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jan 2021 21:32:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unknown-Subtraction-Issue/m-p/711291#M219093</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-01-13T21:32:17Z</dc:date>
    </item>
    <item>
      <title>Re: Unknown Subtraction Issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unknown-Subtraction-Issue/m-p/711293#M219094</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    input Total1-Total9;
    datalines;
. 1 1 1 1 1 1 1 1
1 . 1 1 1 1 1 1 1
1 1 . 1 1 1 1 1 1
1 1 1 . 1 1 1 1 1
1 1 1 1 . 1 1 1 1
1 1 1 1 1 . 1 1 1
1 1 1 1 1 1 . 1 1
1 1 1 1 1 1 1 . 1
1 1 1 1 1 1 1 1 .
    ;
run;

data want;
    set have;
    TotalCount = sum(sum(of Total1 -- Total8), -Total9);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Jan 2021 21:33:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unknown-Subtraction-Issue/m-p/711293#M219094</guid>
      <dc:creator>mklangley</dc:creator>
      <dc:date>2021-01-13T21:33:02Z</dc:date>
    </item>
    <item>
      <title>Re: Unknown Subtraction Issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unknown-Subtraction-Issue/m-p/711321#M219109</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/349857"&gt;@BlayLay&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;No luck...still missing values as output&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I did not say you would get a result, but you don't have logic or syntax errors.&lt;/P&gt;
&lt;P&gt;Provide example values of all 9 variables where the result is missing and what you expect for a result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best would be as a data step.&lt;/P&gt;
&lt;P&gt;Have you been trying to use -Total9 as part of the Sum function because Total9 is sometimes missing and want the sum of the rest in that case?&lt;/P&gt;
&lt;P&gt;Or are you just trying to remove the note from the log?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any subtraction operation will result in a missing result if the value of any of the operands is missing.&lt;/P&gt;
&lt;P&gt;If you expect 10 - .&amp;nbsp; to have a value of 10 then your "missing" is incorrect and requires a value of 0 for numeric operations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you don't want the note, as &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; said, you need to check the value before the subtraction:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;if not missing(total9) then TotalCount = sum(of Total1 -- Total8) - Total9;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;but, unless you tell what you expect as a non-missing result there is no way to provide one.&lt;/P&gt;
&lt;P&gt;A special missing could be provide if Total9 is missing to indicate that was why.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;if not missing(total9) then TotalCount = sum(of Total1 -- Total8) - Total9;
else TotalCount = .N;&lt;/PRE&gt;
&lt;P&gt;The .N is still missing and is used in numeric calculation just like missing but you can display the value, best with a custom format, that lets you know specifically why it was missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What do you expect for a value when Total1 through Total 8 are missing but Total9 is not?&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jan 2021 23:21:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unknown-Subtraction-Issue/m-p/711321#M219109</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-01-13T23:21:44Z</dc:date>
    </item>
    <item>
      <title>Re: Unknown Subtraction Issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unknown-Subtraction-Issue/m-p/711327#M219111</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp; to your point, "&lt;SPAN&gt;Any subtraction operation will result in a missing result if the value of any of the operands is missing" was my concern and why I didn't go with a basic subtraction function. Due to the fact some columns may have missing values. Below is a small-scale example, and i've added "TotalCount" as the desired output. Same concept applies, summing (Total1 -- Total2) and then subtracting Total3 to get TotalCount.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="25%" height="29px"&gt;Total1&lt;/TD&gt;
&lt;TD width="25%" height="29px"&gt;Total2&lt;/TD&gt;
&lt;TD width="25%" height="29px"&gt;Total3&lt;/TD&gt;
&lt;TD width="25%" height="29px"&gt;TotalCount&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%" height="29px" class="lia-align-center"&gt;1&lt;/TD&gt;
&lt;TD width="25%" height="29px" class="lia-align-center"&gt;0&lt;/TD&gt;
&lt;TD width="25%" height="29px" class="lia-align-center"&gt;1&lt;/TD&gt;
&lt;TD width="25%" height="29px" class="lia-align-center"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%" height="29px" class="lia-align-center"&gt;1&lt;/TD&gt;
&lt;TD width="25%" height="29px" class="lia-align-center"&gt;1&lt;/TD&gt;
&lt;TD width="25%" height="29px" class="lia-align-center"&gt;.&lt;/TD&gt;
&lt;TD width="25%" height="29px" class="lia-align-center"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%" height="29px" class="lia-align-center"&gt;0&lt;/TD&gt;
&lt;TD width="25%" height="29px" class="lia-align-center"&gt;0&lt;/TD&gt;
&lt;TD width="25%" height="29px" class="lia-align-center"&gt;1&lt;/TD&gt;
&lt;TD width="25%" height="29px" class="lia-align-center"&gt;-1&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/223296"&gt;@mklangley&lt;/a&gt;&amp;nbsp; code seems to work, however, I just wanted to make sure that I'm going about this correctly.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jan 2021 00:25:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unknown-Subtraction-Issue/m-p/711327#M219111</guid>
      <dc:creator>BlayLay</dc:creator>
      <dc:date>2021-01-14T00:25:55Z</dc:date>
    </item>
    <item>
      <title>Re: Unknown Subtraction Issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unknown-Subtraction-Issue/m-p/711392#M219147</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/349857"&gt;@BlayLay&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is good practice to use IF conditions to deal with missing values appropriately and to avoid notes like "&lt;FONT face="courier new,courier"&gt;Missing values were generated ...&lt;/FONT&gt;" in the log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
if n(of Total1-Total8)=0 then TotalCount=.;
else TotalCount=sum(of Total1-Total8);
if n(Total9) then TotalCount=sum(TotalCount, -Total9);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This will result in a missing value of &lt;FONT face="courier new,courier"&gt;TotalCount&lt;/FONT&gt; only if all nine totals are missing. In all other cases missing values are treated as zeros in the calculation. If your rules are different, it will be no problem to adapt the code correspondingly.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jan 2021 10:17:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unknown-Subtraction-Issue/m-p/711392#M219147</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-01-14T10:17:12Z</dc:date>
    </item>
    <item>
      <title>Re: Unknown Subtraction Issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unknown-Subtraction-Issue/m-p/711564#M219222</link>
      <description>&lt;P&gt;You can use an extra SUM() function call (or a COALESCE() function call) to handle the missing values without notes in the log.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;total=sum(of x1-x3,-sum(0,x4));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But that will return zero when all values are missing.&amp;nbsp; If you want missing in that&amp;nbsp; case then test whether there is at least one non-missing value. You could use the N() function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a simple example with 4 input variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  do x1=.,1; do x2=.,2; do x3=.,4; do x4=.,1;
    output;
  end;end;end;end;
run;

data want;
  set test;
  if n(of x1-x4) then total=sum(of x1-x3,-sum(0,x4));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;Obs    x1    x2    x3    x4    total

  1     .     .     .     .       .
  2     .     .     .     1      -1
  3     .     .     4     .       4
  4     .     .     4     1       3
  5     .     2     .     .       2
  6     .     2     .     1       1
  7     .     2     4     .       6
  8     .     2     4     1       5
  9     1     .     .     .       1
 10     1     .     .     1       0
 11     1     .     4     .       5
 12     1     .     4     1       4
 13     1     2     .     .       3
 14     1     2     .     1       2
 15     1     2     4     .       7
 16     1     2     4     1       6
&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Jan 2021 21:41:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unknown-Subtraction-Issue/m-p/711564#M219222</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-01-14T21:41:15Z</dc:date>
    </item>
  </channel>
</rss>

