<?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 sum in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/sum/m-p/858651#M339253</link>
    <description>&lt;P&gt;what does it mean when we specify values in sum?&lt;/P&gt;
&lt;P&gt;I tried this and it does not add up, ..&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is there special meaning when we specify like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;fruit=sum(apple='1',orange='2',lemon='3')&lt;/PRE&gt;
&lt;P&gt;fruit is not 6 but show noting in output&lt;/P&gt;</description>
    <pubDate>Tue, 14 Feb 2023 02:53:20 GMT</pubDate>
    <dc:creator>HeatherNewton</dc:creator>
    <dc:date>2023-02-14T02:53:20Z</dc:date>
    <item>
      <title>sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum/m-p/858651#M339253</link>
      <description>&lt;P&gt;what does it mean when we specify values in sum?&lt;/P&gt;
&lt;P&gt;I tried this and it does not add up, ..&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is there special meaning when we specify like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;fruit=sum(apple='1',orange='2',lemon='3')&lt;/PRE&gt;
&lt;P&gt;fruit is not 6 but show noting in output&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2023 02:53:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum/m-p/858651#M339253</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2023-02-14T02:53:20Z</dc:date>
    </item>
    <item>
      <title>Re: sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum/m-p/858654#M339254</link>
      <description>&lt;P&gt;You can easily test how this works yourself:&lt;/P&gt;
&lt;PRE&gt;28         data _null_;
29           apple = '1';
30           orange = '1';
31           fruit = sum(apple = '1', orange = '1');
32           put _all_;
33         run;

apple=1 orange=1 fruit=2 _ERROR_=0 _N_=1
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds&lt;/PRE&gt;
&lt;P&gt;Summing conditions like apple = '1' turns them into Boolean true = 1 or false = 0 values that are then added.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2023 03:12:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum/m-p/858654#M339254</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-02-14T03:12:16Z</dc:date>
    </item>
    <item>
      <title>Re: sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum/m-p/858661#M339259</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/416388"&gt;@HeatherNewton&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;what does it mean when we specify values in sum?&lt;/P&gt;
&lt;P&gt;I tried this and it does not add up, ..&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is there special meaning when we specify like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;fruit=sum(apple='1',orange='2',lemon='3')&lt;/PRE&gt;
&lt;P&gt;fruit is not 6 but show noting in output&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;SAS returns 1 for a true result of a logical comparison and 0 for false. So when apple='1' you get a 1 and 0 otherwise. Summing these comparisons is a way to COUNT how many are true.&lt;/P&gt;
&lt;P&gt;This internal creation of a numbers will execute much faster than a bunch of If/then/else that might be another attempt to count such as:&lt;/P&gt;
&lt;PRE&gt;Count=0;
if apple='1' then count=count+1;
if orange='2' then count=count+1;
if lemon='3' then count=count+1;&lt;/PRE&gt;
&lt;P&gt;By "tried this" how many different values of apple, orange and lemon did you try?&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2023 05:40:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum/m-p/858661#M339259</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-02-14T05:40:16Z</dc:date>
    </item>
  </channel>
</rss>

