<?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: sum function and missing value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/sum-function-and-missing-value/m-p/421012#M103584</link>
    <description>&lt;P&gt;Of course you could also use the opposite of nmiss, namely:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  if n(of acd--ocd) ne 0 then sum=sum(of acd--ocd);
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 13 Dec 2017 22:32:45 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2017-12-13T22:32:45Z</dc:date>
    <item>
      <title>sum function and missing value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-function-and-missing-value/m-p/420995#M103578</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I am trying to sum all values of some variables.&lt;/P&gt;&lt;P&gt;Variables acd,bcd,.......ocd have either a value of 1,0, or missing&lt;/P&gt;&lt;P&gt;So in order to get the total, I used the sum function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data total;&lt;BR /&gt;set start;&lt;BR /&gt;count= sum(acd, bcd, ccd, dcd, ecd, fcd, gcd, hcd, icd, jcd, kcd, lcd, mcd, ncd, ocd);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But&amp;nbsp; I get an error message&amp;nbsp; on the log saying&lt;/P&gt;&lt;P&gt;Missing values were generated as a result of performing an operation on missing values&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What is wrong with my sum statement?&lt;/P&gt;&lt;P&gt;thanks&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;</description>
      <pubDate>Wed, 13 Dec 2017 21:38:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-function-and-missing-value/m-p/420995#M103578</guid>
      <dc:creator>leahcho</dc:creator>
      <dc:date>2017-12-13T21:38:08Z</dc:date>
    </item>
    <item>
      <title>Re: sum function and missing value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-function-and-missing-value/m-p/420997#M103579</link>
      <description>&lt;P&gt;That's not an error. That's merely a NOTE in the log. This happens when all of those variables specified as arguments to sum function have missing values. Take a look below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input a b c;&lt;BR /&gt;datalines;&lt;BR /&gt;1 2 3&lt;BR /&gt;4 . 6&lt;BR /&gt;. . .&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;sum=sum(a,b,c);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;Try running the second time by removing the last dataline in HAVE. You'll understand&lt;/P&gt;&lt;P&gt;And if you do not want such notes, set &lt;STRONG&gt;nonotes system option&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 21:44:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-function-and-missing-value/m-p/420997#M103579</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-12-13T21:44:02Z</dc:date>
    </item>
    <item>
      <title>Re: sum function and missing value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-function-and-missing-value/m-p/420999#M103580</link>
      <description>&lt;P&gt;A few things to consider ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, the DATA step sums values within a single observation.&amp;nbsp; Is that what you want, or do you want a sum each variable separately, across all observations?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second, SUM returns a missing value when all the incoming values are missing.&amp;nbsp; That's what gets you the note in the log.&amp;nbsp; You could add one more argument to the SUM function, adding 0 to the list of values being summed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Finally, if you want each variable summed individually across all observations, it is easy to use PROC MEANS:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc means data=have;&lt;/P&gt;
&lt;P&gt;var acd bcd ccd dcd ecd fcd gcd hcd icd jcd kcd lcd mcd ncd ocd;&lt;/P&gt;
&lt;P&gt;output out=save_in_a_data_set_also sum=;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc print data=save_in_a_data_set_also;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 21:43:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-function-and-missing-value/m-p/420999#M103580</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-12-13T21:43:40Z</dc:date>
    </item>
    <item>
      <title>Re: sum function and missing value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-function-and-missing-value/m-p/421007#M103581</link>
      <description>Thanks. now I understand what is happening. Is it possible to write a statement to ignore rows with missing values and add other rows that have some 1s and 0s? so that I can skip rows with all missing values?&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 13 Dec 2017 22:08:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-function-and-missing-value/m-p/421007#M103581</guid>
      <dc:creator>leahcho</dc:creator>
      <dc:date>2017-12-13T22:08:06Z</dc:date>
    </item>
    <item>
      <title>Re: sum function and missing value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-function-and-missing-value/m-p/421008#M103582</link>
      <description>&lt;P&gt;sure try the subsetting if before you sum:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;if&amp;nbsp;cmiss(of a--c) eq 0&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input a b c;&lt;BR /&gt;datalines;&lt;BR /&gt;1 2 3&lt;BR /&gt;4 . 6&lt;BR /&gt;. . .&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;&lt;STRONG&gt;if cmiss(of a--c) eq 0;&lt;/STRONG&gt;&lt;BR /&gt;sum=sum(a,b,c);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And if you want to keep the records with missing values in your output, then--&amp;gt;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;&lt;STRONG&gt;if cmiss(of a--c) eq 0 then sum=sum(a,b,c);&lt;/STRONG&gt;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 22:14:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-function-and-missing-value/m-p/421008#M103582</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-12-13T22:14:54Z</dc:date>
    </item>
    <item>
      <title>Re: sum function and missing value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-function-and-missing-value/m-p/421010#M103583</link>
      <description>&lt;P&gt;One slight(?) correction to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;'s suggested code. cmiss counts the number of missing values so what you'd want is:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  if cmiss(acd, bcd, ccd, dcd, ecd, fcd, gcd, hcd, icd, jcd, kcd, lcd, mcd, ncd, ocd) ne 15
   then sum=sum(acd, bcd, ccd, dcd, ecd, fcd, gcd, hcd, icd, jcd, kcd, lcd, mcd, ncd, ocd);
run;
&lt;/PRE&gt;
&lt;P&gt;However, if your variables are in the same order as shown above, you could use the same type of&amp;nbsp;variable list used in that suggested code, namely:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  if cmiss(of acd--ocd) ne 3 then sum=sum(of acd--ocd);
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 22:24:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-function-and-missing-value/m-p/421010#M103583</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-12-13T22:24:16Z</dc:date>
    </item>
    <item>
      <title>Re: sum function and missing value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-function-and-missing-value/m-p/421012#M103584</link>
      <description>&lt;P&gt;Of course you could also use the opposite of nmiss, namely:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  if n(of acd--ocd) ne 0 then sum=sum(of acd--ocd);
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 22:32:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-function-and-missing-value/m-p/421012#M103584</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-12-13T22:32:45Z</dc:date>
    </item>
    <item>
      <title>Re: sum function and missing value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-function-and-missing-value/m-p/421027#M103586</link>
      <description>I am trying to sum all variables per each ID and create a variable for that&lt;BR /&gt;So the data have&lt;BR /&gt;ID acd bcd ccd ...ocd&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; total_ct&lt;BR /&gt;1&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;BR /&gt;2&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;BR /&gt;&lt;BR /&gt;So I want to create total_ct variable but I have some rows with all variable values missing&lt;BR /&gt;</description>
      <pubDate>Wed, 13 Dec 2017 23:15:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-function-and-missing-value/m-p/421027#M103586</guid>
      <dc:creator>leahcho</dc:creator>
      <dc:date>2017-12-13T23:15:10Z</dc:date>
    </item>
    <item>
      <title>Re: sum function and missing value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-function-and-missing-value/m-p/421029#M103587</link>
      <description>&lt;P&gt;Do you want to output the records that only have missing values?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 23:19:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-function-and-missing-value/m-p/421029#M103587</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-12-13T23:19:21Z</dc:date>
    </item>
    <item>
      <title>Re: sum function and missing value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-function-and-missing-value/m-p/421035#M103589</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/151476"&gt;@leahcho&lt;/a&gt; wrote:&lt;BR /&gt;I am trying to sum all variables per each ID and create a variable for that&lt;BR /&gt;So the data have&lt;BR /&gt;ID acd bcd ccd ...ocd&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; total_ct&lt;BR /&gt;1&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;BR /&gt;2&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;BR /&gt;&lt;BR /&gt;So I want to create total_ct variable but I have some rows with all variable values missing&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So do want a special value for the total when all are missing? Not to output the row with a missing total? Something else?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So far there is no issue, that is what the function does. If you need a specific result for the missing then tell us.&lt;/P&gt;
&lt;P&gt;Or use&lt;/P&gt;
&lt;P&gt;if missing (total_ct) then total_ct = &amp;lt;what ever &lt;STRONG&gt;numeric&lt;/STRONG&gt; value you want&amp;gt;. Or delve in the joys of special missing values.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 23:43:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-function-and-missing-value/m-p/421035#M103589</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-12-13T23:43:54Z</dc:date>
    </item>
  </channel>
</rss>

