<?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: How come SAS Accepts Sum = Sum (Sum, Age) ; ? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-come-SAS-Accepts-Sum-Sum-Sum-Age/m-p/93338#M26517</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Mirasage,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Art makes good point about sas allows the use of a function name for a variable name.&amp;nbsp; Other programming languages might not let you do this. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But I think you also highlight another issue leading to confusion is that the equal sign is used both as a logical operater and to indicate an assign statement.&amp;nbsp; Algebraic rules to not hold for both sides of an assignment statement.&amp;nbsp; For example: the assignment statement Sum = Sum (Sum, Age)&amp;nbsp; means the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Sum the previous value of the variable SUM and the variable Age&lt;/P&gt;&lt;P&gt;2. Take the results from 1 and replace the value of the variable SUM with that value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;On the other hand, if that expression where used as a logical expression, such as, 'IF Sum = Sum (Sum, Age)" would only be true if the value of Age is either missing or 0 (zero). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Larry &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 12 Oct 2012 16:33:01 GMT</pubDate>
    <dc:creator>LarryWorley</dc:creator>
    <dc:date>2012-10-12T16:33:01Z</dc:date>
    <item>
      <title>How come SAS Accepts Sum = Sum (Sum, Age) ; ?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-come-SAS-Accepts-Sum-Sum-Sum-Age/m-p/93336#M26515</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN lang="EN" style="font-family: Helvetica; color: #575757; font-size: 11pt;"&gt;Hi Forum,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN" style="font-family: Helvetica; color: #575757; font-size: 11pt;"&gt;&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN" style="font-family: Helvetica; color: #575757; font-size: 11pt;"&gt;In this DOW Loop, could anyone please elaborate the logic of the equation highlighted by yellow? &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN" style="font-family: Helvetica; color: #575757; font-size: 11pt;"&gt;&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN" style="font-family: Helvetica; color: #575757; font-size: 11pt;"&gt;In normal arithmetic I am familiar, these are logically correct:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN" style="font-family: Helvetica; color: #575757; font-size: 11pt;"&gt;Sum = Sum or Sum= Sum*1&amp;nbsp; or Sum = Sum +0 etc. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN" style="font-family: Helvetica; color: #575757; font-size: 11pt;"&gt;&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN" style="font-family: Helvetica; color: #575757; font-size: 11pt;"&gt;But SAS works really well when you say &lt;SPAN style="background: yellow;"&gt;Sum = Sum (Sum, Age) but how come?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN" style="font-family: Helvetica; color: #575757; font-size: 11pt;"&gt;&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN" style="font-family: Helvetica; color: #575757; font-size: 11pt;"&gt;Data B ( Keep = Sex MCountSum Mean) ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; Do Until ( Last.Sex ) ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; Set Class ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; By Sex;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If Missing (Age) Then Continue ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MCount = Sum (MCount, 1) ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="background: yellow;"&gt;Sum = Sum (Sum, Age) ;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; put _ALL_; /* look in the SAS LOG to see each iteration */&lt;BR /&gt;&amp;nbsp;&amp;nbsp; End;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; Mean = Sum / MCount;&lt;BR /&gt;Run ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN" style="font-family: Helvetica; color: #575757; font-size: 11pt;"&gt;&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN" style="font-family: Helvetica; color: #575757; font-size: 11pt;"&gt;&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN" style="font-family: Helvetica; color: #ff0000; font-size: 11pt;"&gt;Also I found in some other place &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN" style="font-family: Helvetica; color: #ff0000; font-size: 11pt;"&gt;Total = Total + Interest * Total&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN" style="font-family: Helvetica; color: #575757; font-size: 11pt;"&gt;&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN" style="font-family: Helvetica; color: #575757; font-size: 11pt;"&gt;In above case, the equation is true only if Interest = 0, isn’t it?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN" style="font-family: Helvetica; color: #575757; font-size: 11pt;"&gt;But SAS accepts Total = Total + Interest * Total&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN" style="font-family: Helvetica; color: #575757; font-size: 11pt;"&gt;&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN" style="font-family: Helvetica; color: #575757; font-size: 11pt;"&gt;Thank you&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN" style="font-family: Helvetica; color: #575757; font-size: 11pt;"&gt;Mirisage&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Oct 2012 15:51:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-come-SAS-Accepts-Sum-Sum-Sum-Age/m-p/93336#M26515</guid>
      <dc:creator>Mirisage</dc:creator>
      <dc:date>2012-10-12T15:51:27Z</dc:date>
    </item>
    <item>
      <title>Re: How come SAS Accepts Sum = Sum (Sum, Age) ; ?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-come-SAS-Accepts-Sum-Sum-Sum-Age/m-p/93337#M26516</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Mirisage: SAS lets one use function names as variable names.&amp;nbsp; The equations are true or false, they represent calculations.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When using the sum function, the result will only be missing if all of the parts are missing.&lt;/P&gt;&lt;P&gt;When one uses a statement like "&lt;SPAN style="color: #ff0000; font-family: Helvetica; font-size: 15px; background-color: #ffffff;"&gt;Total = Total + Interest * Total&lt;/SPAN&gt;" the result will be a missing value if ANY part is missing.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Oct 2012 16:19:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-come-SAS-Accepts-Sum-Sum-Sum-Age/m-p/93337#M26516</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-10-12T16:19:18Z</dc:date>
    </item>
    <item>
      <title>Re: How come SAS Accepts Sum = Sum (Sum, Age) ; ?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-come-SAS-Accepts-Sum-Sum-Sum-Age/m-p/93338#M26517</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Mirasage,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Art makes good point about sas allows the use of a function name for a variable name.&amp;nbsp; Other programming languages might not let you do this. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But I think you also highlight another issue leading to confusion is that the equal sign is used both as a logical operater and to indicate an assign statement.&amp;nbsp; Algebraic rules to not hold for both sides of an assignment statement.&amp;nbsp; For example: the assignment statement Sum = Sum (Sum, Age)&amp;nbsp; means the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Sum the previous value of the variable SUM and the variable Age&lt;/P&gt;&lt;P&gt;2. Take the results from 1 and replace the value of the variable SUM with that value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;On the other hand, if that expression where used as a logical expression, such as, 'IF Sum = Sum (Sum, Age)" would only be true if the value of Age is either missing or 0 (zero). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Larry &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Oct 2012 16:33:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-come-SAS-Accepts-Sum-Sum-Sum-Age/m-p/93338#M26517</guid>
      <dc:creator>LarryWorley</dc:creator>
      <dc:date>2012-10-12T16:33:01Z</dc:date>
    </item>
    <item>
      <title>Re: How come SAS Accepts Sum = Sum (Sum, Age) ; ?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-come-SAS-Accepts-Sum-Sum-Sum-Age/m-p/93339#M26518</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Helvetica; font-size: 15px; background-color: #ffffff;"&gt;Total = Total + Interest * Total ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Helvetica; font-size: 15px; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Helvetica; font-size: 15px; background-color: #ffffff;"&gt;Is an assignment statement.&amp;nbsp; So you wouldn't normally think of it as having a truth value.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Helvetica; font-size: 15px; background-color: #ffffff;"&gt;It will add the calculated interest to the total variable.&amp;nbsp; Mathematically equivalent to TOTAL = (1 + INTEREST) * TOTAL.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Helvetica; font-size: 15px; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Helvetica; font-size: 15px; background-color: #ffffff;"&gt;If INTEREST is missing then the new value of TOTAL will be missing.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Helvetica; font-size: 15px; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Helvetica; font-size: 15px; background-color: #ffffff;"&gt;If instead you use the SUM() function &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Helvetica; font-size: 15px; background-color: #ffffff;"&gt;TOTAL=sum(TOTAL,INTEREST*TOTAL);&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Helvetica; font-size: 15px; background-color: #ffffff;"&gt;or the sum operator &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Helvetica; font-size: 15px; background-color: #ffffff;"&gt;TOTAL+(INTEREST*TOTAL);&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Helvetica; font-size: 15px; background-color: #ffffff;"&gt;then missing values will be ignored.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000; font-family: Helvetica; font-size: 15px; background-color: #ffffff;"&gt;Note that the sum operator will also mark the target variable (TOTAL) to be retained across data step iterations.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000; font-family: Helvetica; font-size: 15px; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Oct 2012 17:21:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-come-SAS-Accepts-Sum-Sum-Sum-Age/m-p/93339#M26518</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-10-12T17:21:16Z</dc:date>
    </item>
  </channel>
</rss>

