<?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 Confused by how sas handles missing values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Confused-by-how-sas-handles-missing-values/m-p/282396#M57388</link>
    <description>&lt;P&gt;I'm confused about the way SAS handles missing values. I've recently realized I have to be very careful about assuming what SAS will do when it encounters a missing value. Here is a simple example.&lt;/P&gt;&lt;PRE&gt;data _null_;
a = .;
b = a + 1;
c = sum(a,1);
a+1;

put a= b= c=;
run;&lt;/PRE&gt;&lt;P&gt;The result is:&amp;nbsp;a=1 b=. c=1&lt;/P&gt;&lt;P&gt;This means that adding 1 to missing with + results in missing, but adding 1 to missing with either the sum function or increment operator results in 1. Is there any logical reason for this behavior?&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Wed, 06 Jul 2016 12:38:21 GMT</pubDate>
    <dc:creator>Adam_Black</dc:creator>
    <dc:date>2016-07-06T12:38:21Z</dc:date>
    <item>
      <title>Confused by how sas handles missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Confused-by-how-sas-handles-missing-values/m-p/282396#M57388</link>
      <description>&lt;P&gt;I'm confused about the way SAS handles missing values. I've recently realized I have to be very careful about assuming what SAS will do when it encounters a missing value. Here is a simple example.&lt;/P&gt;&lt;PRE&gt;data _null_;
a = .;
b = a + 1;
c = sum(a,1);
a+1;

put a= b= c=;
run;&lt;/PRE&gt;&lt;P&gt;The result is:&amp;nbsp;a=1 b=. c=1&lt;/P&gt;&lt;P&gt;This means that adding 1 to missing with + results in missing, but adding 1 to missing with either the sum function or increment operator results in 1. Is there any logical reason for this behavior?&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jul 2016 12:38:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Confused-by-how-sas-handles-missing-values/m-p/282396#M57388</guid>
      <dc:creator>Adam_Black</dc:creator>
      <dc:date>2016-07-06T12:38:21Z</dc:date>
    </item>
    <item>
      <title>Re: Confused by how sas handles missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Confused-by-how-sas-handles-missing-values/m-p/282406#M57393</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What you expect when saying logical behaviour ?&lt;/P&gt;
&lt;P&gt;YOu can find documentation which explains each one of your examples:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;sum statement&lt;/STRONG&gt; : &lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000289454.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000289454.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;sum function&lt;/STRONG&gt;: &lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000245953.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000245953.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;sum operator&lt;/STRONG&gt;: &lt;A href="http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/viewer.htm#a001334675.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/viewer.htm#a001334675.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jul 2016 13:06:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Confused-by-how-sas-handles-missing-values/m-p/282406#M57393</guid>
      <dc:creator>Loko</dc:creator>
      <dc:date>2016-07-06T13:06:30Z</dc:date>
    </item>
    <item>
      <title>Re: Confused by how sas handles missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Confused-by-how-sas-handles-missing-values/m-p/282410#M57395</link>
      <description>&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&lt;U&gt;SAS functions ignore missing values in their computation&lt;/U&gt;.&lt;/STRONG&gt; So with the SUM function, the sum of 2 and a missing value is 2, whether it is missing with the + operator: 2 + . = . If you read on &lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000245953.htm" target="_self"&gt;support &lt;/A&gt;the SUM statement confirm you're argumentation. &lt;A href="http://www.lexjansen.com/nesug/nesug06/cc/cc31.pdf" target="_self"&gt;Here &lt;/A&gt;there's a clear paper on topic. &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;hope this helps &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;have nice day&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jul 2016 13:18:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Confused-by-how-sas-handles-missing-values/m-p/282410#M57395</guid>
      <dc:creator>MC1985</dc:creator>
      <dc:date>2016-07-06T13:18:59Z</dc:date>
    </item>
    <item>
      <title>Re: Confused by how sas handles missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Confused-by-how-sas-handles-missing-values/m-p/282435#M57400</link>
      <description>&lt;P&gt;The documents mentioned explain the difference between SUM FUNCTION and SUM STATEMENT.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A simple way is to look at the following two data steps.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The first data step works with SUM STATEMENT.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   b = a + 1;
   put b = ;
run;&lt;BR /&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When the data step starts, both A and B are assigned with missing values. Even if you insert a statement,( A = .; ) as a first line in the program, still a is missing but avoids a NOTE(Variable A is uninitialized).&lt;/P&gt;&lt;P&gt;So, in Sum statement, using a missing value results in a missing value. This is how SAS works. You can explore the use of RETAIN Statement further.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The second works with the SUM Function:&lt;/P&gt;&lt;P&gt;At the beginning of the data step both A and C are assigned with missing values. When the data step COMPILES, the use of SUM function is noted, and it makes A to take zero value when the data step starts execution( the RETAIN statement is used with zero, behind the scene). Hence, C becomes zero + 1. However, SAS writes a NOTE(Variable A is uninitialized).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hence, SAS treats SUM Statement and SUM Function differently.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   c = sum(a, 1);
   put c = ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Jul 2016 14:16:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Confused-by-how-sas-handles-missing-values/m-p/282435#M57400</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2016-07-06T14:16:32Z</dc:date>
    </item>
    <item>
      <title>Re: Confused by how sas handles missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Confused-by-how-sas-handles-missing-values/m-p/282453#M57410</link>
      <description>&lt;P&gt;Why the behaviors:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Some times you do not want to include the value but need the sum of non-missing so that is the behavior of the SUM function. For instance I have variables that represent sales of different products but not every customer buys every product. If I want to know how much a customer spent I want to total all non-missing product sales: SUM Function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For some things I may require that I calculate the sum only when every value is populated. Is if fair to compare totals of quarterly sales for a salesman that only worked 1 quarter of the year and not 4? So I use the addition so that I only have sums for salesmen that worked all 4 quarters (obviously I would do something else for the other salesmen).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since the primary purpose of the A+1; syntax is a counter it makes a lot of sense that after the first increment a "missing" has one added to indicate the count was completed. NOTE that the syntax also implies a RETAIN statement for the variable A and behaves quite differently.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jul 2016 15:34:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Confused-by-how-sas-handles-missing-values/m-p/282453#M57410</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-07-06T15:34:43Z</dc:date>
    </item>
    <item>
      <title>Re: Confused by how sas handles missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Confused-by-how-sas-handles-missing-values/m-p/282480#M57413</link>
      <description>&lt;P&gt;Thanks for the documentation references. I was expecting all three of the the methods that add one to the variable 'a' to give me the same result. Also I mistakenly thought that the sum statement, "a+1;", &amp;nbsp;is equivalent to "a = a +1;"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In fact,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the sum statement is equivalent to using the SUM function and the RETAIN statement, as shown here:&lt;/P&gt;&lt;PRE&gt;retain &lt;SPAN class="emphMono"&gt;variable&lt;/SPAN&gt; 0;
&lt;SPAN class="emphMono"&gt;variable&lt;/SPAN&gt;=sum(&lt;SPAN class="emphMono"&gt;variable&lt;/SPAN&gt;,&lt;SPAN class="emphMono"&gt;expression&lt;/SPAN&gt;);&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jul 2016 16:54:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Confused-by-how-sas-handles-missing-values/m-p/282480#M57413</guid>
      <dc:creator>Adam_Black</dc:creator>
      <dc:date>2016-07-06T16:54:34Z</dc:date>
    </item>
  </channel>
</rss>

