<?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: Dif Statement Works Properly for Some, but not All Records in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Dif-Statement-Works-Properly-for-Some-but-not-All-Records/m-p/648946#M36064</link>
    <description>&lt;P&gt;We can't diagnose your code without seeing it.&amp;nbsp; Please post the code (using the popup window generated by clicking on the "running max" icon).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 19 May 2020 18:24:32 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2020-05-19T18:24:32Z</dc:date>
    <item>
      <title>Dif Statement Works Properly for Some, but not All Records</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Dif-Statement-Works-Properly-for-Some-but-not-All-Records/m-p/648944#M36063</link>
      <description>&lt;P&gt;I generated code that I can't seem to get it to work right. It seems to work fine for most records but I occasionally have records with an issue and I can't figure out what I'm doing wrong.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In looking at the following table, how do I get OP_CALC for the first record to equal the Balance_Amt and have all subsequent records calculate the dif of the previous amount? In other words, OP_Calc for COUNT 2 should be -250.03. For some reason, my code seems to be treating the second record in this example as the first.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;COUNT&lt;/TD&gt;&lt;TD&gt;Applied_Amt&lt;/TD&gt;&lt;TD&gt;Balance_Amt&lt;/TD&gt;&lt;TD&gt;OP_CALC&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;503&lt;/TD&gt;&lt;TD&gt;503&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;250.03&lt;/TD&gt;&lt;TD&gt;252.97&lt;/TD&gt;&lt;TD&gt;252.97&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;502&lt;/TD&gt;&lt;TD&gt;-249.03&lt;/TD&gt;&lt;TD&gt;-502&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;-249.03&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;249.03&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;250&lt;/TD&gt;&lt;TD&gt;-250&lt;/TD&gt;&lt;TD&gt;-250&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;-250&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;250&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&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>Tue, 19 May 2020 18:12:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Dif-Statement-Works-Properly-for-Some-but-not-All-Records/m-p/648944#M36063</guid>
      <dc:creator>ArmyMP</dc:creator>
      <dc:date>2020-05-19T18:12:23Z</dc:date>
    </item>
    <item>
      <title>Re: Dif Statement Works Properly for Some, but not All Records</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Dif-Statement-Works-Properly-for-Some-but-not-All-Records/m-p/648946#M36064</link>
      <description>&lt;P&gt;We can't diagnose your code without seeing it.&amp;nbsp; Please post the code (using the popup window generated by clicking on the "running max" icon).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 May 2020 18:24:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Dif-Statement-Works-Properly-for-Some-but-not-All-Records/m-p/648946#M36064</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-05-19T18:24:32Z</dc:date>
    </item>
    <item>
      <title>Re: Dif Statement Works Properly for Some, but not All Records</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Dif-Statement-Works-Properly-for-Some-but-not-All-Records/m-p/648949#M36065</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA OP_CALC;
SET WORK.ACCT_BAL_DTL;
  by CLMEVNTID CLMACCNTBLNCDT;
  if first.CLMEVNTID then
	  COUNT=1;
	else COUNT + 1;
run;
	
DATA OP_CALC_2;
SET WORK.OP_CALC;
  by CLMEVNTID COUNT;
  if COUNT=1 AND Balance_Amt&amp;gt;0 then
	  OP_CALC=Balance_Amt;
	else OP_CALC=dif(Balance_Amt);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 May 2020 18:31:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Dif-Statement-Works-Properly-for-Some-but-not-All-Records/m-p/648949#M36065</guid>
      <dc:creator>ArmyMP</dc:creator>
      <dc:date>2020-05-19T18:31:32Z</dc:date>
    </item>
    <item>
      <title>Re: Dif Statement Works Properly for Some, but not All Records</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Dif-Statement-Works-Properly-for-Some-but-not-All-Records/m-p/648987#M36066</link>
      <description>&lt;P&gt;The Dif and Lag functions run queues. So the "last value" is the value from the last time a condition was true. If you always want the immediately previous value to be used in the assignment then create a temporary value out side of any conditional statement and then use that value as needed. Such as:&lt;/P&gt;
&lt;PRE&gt;DATA OP_CALC_2;
SET WORK.OP_CALC;
  by CLMEVNTID COUNT;
  difval=dif(Balance_Amt);
  if COUNT=1 AND Balance_Amt&amp;gt;0 then
	  OP_CALC=Balance_Amt;
  else OP_CALC=difval;
  drop difval;
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 May 2020 19:20:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Dif-Statement-Works-Properly-for-Some-but-not-All-Records/m-p/648987#M36066</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-05-19T19:20:55Z</dc:date>
    </item>
    <item>
      <title>Re: Dif Statement Works Properly for Some, but not All Records</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Dif-Statement-Works-Properly-for-Some-but-not-All-Records/m-p/648989#M36067</link>
      <description>&lt;P&gt;All functions that work with lagged values must not be called conditionally.&lt;/P&gt;
&lt;P&gt;Restructure your code like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data op_calc_2;
set op_calc;
by CLMEVNTID COUNT;
OP_CALC = dif(Balance_Amt);
if COUNT = 1 and Balance_Amt &amp;gt; 0 then OP_CALC = Balance_Amt;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 May 2020 19:25:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Dif-Statement-Works-Properly-for-Some-but-not-All-Records/m-p/648989#M36067</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-05-19T19:25:07Z</dc:date>
    </item>
    <item>
      <title>Re: Dif Statement Works Properly for Some, but not All Records</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Dif-Statement-Works-Properly-for-Some-but-not-All-Records/m-p/649020#M36068</link>
      <description>&lt;P&gt;Perfect! Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 19 May 2020 21:00:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Dif-Statement-Works-Properly-for-Some-but-not-All-Records/m-p/649020#M36068</guid>
      <dc:creator>ArmyMP</dc:creator>
      <dc:date>2020-05-19T21:00:45Z</dc:date>
    </item>
  </channel>
</rss>

