<?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: difference between two calculation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/difference-between-two-calculation/m-p/364694#M275062</link>
    <description>I see. Thank you</description>
    <pubDate>Tue, 06 Jun 2017 19:20:20 GMT</pubDate>
    <dc:creator>ttxq</dc:creator>
    <dc:date>2017-06-06T19:20:20Z</dc:date>
    <item>
      <title>difference between two calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/difference-between-two-calculation/m-p/364683#M275058</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to know what is the differences between these two statements: (highlighted in red color)&lt;/P&gt;&lt;P&gt;proc sort data=com;&lt;BR /&gt;&amp;nbsp; by dis;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data com;&lt;BR /&gt;&amp;nbsp; set com;&lt;BR /&gt;&amp;nbsp; by dis;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;&amp;nbsp; if first.dis then disn+1; &amp;nbsp; (if&amp;nbsp;&lt;SPAN&gt;first.dis then disn=disn+1)&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;when I run each program, the value of disn is different. I want to know the difference between disn+1 and disn=disn+1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2017 19:00:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/difference-between-two-calculation/m-p/364683#M275058</guid>
      <dc:creator>ttxq</dc:creator>
      <dc:date>2017-06-06T19:00:40Z</dc:date>
    </item>
    <item>
      <title>Re: difference between two calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/difference-between-two-calculation/m-p/364687#M275059</link>
      <description>&lt;P&gt;dsn + 1;&lt;/P&gt;
&lt;P&gt;is a sum statement. &amp;nbsp;It implicitly adds:&lt;/P&gt;
&lt;P&gt;retain dsn 0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;dsn = dsn + 1;&lt;/P&gt;
&lt;P&gt;is an assignment statement. &amp;nbsp;There is no implicit retain.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2017 19:12:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/difference-between-two-calculation/m-p/364687#M275059</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2017-06-06T19:12:54Z</dc:date>
    </item>
    <item>
      <title>Re: difference between two calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/difference-between-two-calculation/m-p/364691#M275060</link>
      <description>&lt;P&gt;When you use a statement like this:&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;if first.dis then disn+1; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;Then the variable DISN is created with an implied Retain statement which means the value is carried from record to record in the data step. If there is a variable in the dataset name in a SET statement then that value gets reset each time a record is pulled from the dataset.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;So the statement as used will increase a count by 1 for each first level of the variable&amp;nbsp;DIS when the statement executes.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;FONT color="#ff0000"&gt;if&amp;nbsp;&lt;/FONT&gt;&lt;SPAN&gt;&lt;FONT color="#ff0000"&gt;first.dis then disn=disn+1&lt;/FONT&gt;&lt;/SPAN&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;FONT color="#000000"&gt;If the variable DISN is not declared with a RETAIN statement and this is the first use then the value of Disn starts as missing. When a missing value has 1 added this way the result is missing. Unless there is a variable Disn in your com set I would expect the result to be missing from the addition. If you do have a Disn variable then the result would be the addition of 1 to that value when not missing.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;FONT color="#000000"&gt;If you need to sum values when something may be missing use the SUM function. However without a retain such as your example the result of disn = sum(disn,1); would likely be 1 for every record.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2017 19:16:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/difference-between-two-calculation/m-p/364691#M275060</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-06-06T19:16:52Z</dc:date>
    </item>
    <item>
      <title>Re: difference between two calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/difference-between-two-calculation/m-p/364692#M275061</link>
      <description>&lt;P&gt;To make it the same, add the RETAIN, if desired.&lt;/P&gt;
&lt;P&gt;This should make disn and disn2 the exact same.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data com1;
set com;
by dis;
retain disn;

if first.dis then disn=disn+1;

if first.dis then disn2+1;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Jun 2017 19:16:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/difference-between-two-calculation/m-p/364692#M275061</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-06-06T19:16:56Z</dc:date>
    </item>
    <item>
      <title>Re: difference between two calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/difference-between-two-calculation/m-p/364694#M275062</link>
      <description>I see. Thank you</description>
      <pubDate>Tue, 06 Jun 2017 19:20:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/difference-between-two-calculation/m-p/364694#M275062</guid>
      <dc:creator>ttxq</dc:creator>
      <dc:date>2017-06-06T19:20:20Z</dc:date>
    </item>
    <item>
      <title>Re: difference between two calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/difference-between-two-calculation/m-p/364695#M275063</link>
      <description>Thanks a lot</description>
      <pubDate>Tue, 06 Jun 2017 19:20:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/difference-between-two-calculation/m-p/364695#M275063</guid>
      <dc:creator>ttxq</dc:creator>
      <dc:date>2017-06-06T19:20:38Z</dc:date>
    </item>
  </channel>
</rss>

