<?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: incremental counter that reset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/incremental-counter-that-reset/m-p/18553#M2804</link>
    <description>Scott,&lt;BR /&gt;
portions of your post were truncated.  your code may have included &amp;lt; or &amp;gt; signs.  Take a look at this link to see how to repost.&lt;BR /&gt;
&lt;A href="http://support.sas.com/forums/thread.jspa?messageID=27609毙" target="_blank"&gt;http://support.sas.com/forums/thread.jspa?messageID=27609毙&lt;/A&gt;</description>
    <pubDate>Wed, 22 Jun 2011 05:18:56 GMT</pubDate>
    <dc:creator>ArtC</dc:creator>
    <dc:date>2011-06-22T05:18:56Z</dc:date>
    <item>
      <title>incremental counter that reset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/incremental-counter-that-reset/m-p/18550#M2801</link>
      <description>hello,&lt;BR /&gt;
&lt;BR /&gt;
I'm trying to create a counter that will reset when criteria is met when comparing the previous record to the current record. Please see my code below. for the datalines (below)  the counter should the following values: 1, 1,2,1,2,3,1. The counter should reset to one if the prev acct number &amp;lt;&amp;gt; to the current record account number + the current_date-previous_date &amp;gt; 50 + the current amt &amp;lt;&amp;gt; the prev amt. &lt;BR /&gt;
Thank you for your help,&lt;BR /&gt;
Scott&lt;BR /&gt;
&lt;BR /&gt;
data work.mytestdata;&lt;BR /&gt;
input acct_nbr $ trans_date $ amt;&lt;BR /&gt;
datalines;&lt;BR /&gt;
12 18638 20&lt;BR /&gt;
12 18669 17&lt;BR /&gt;
12 18711 17 &lt;BR /&gt;
14 18577 14&lt;BR /&gt;
14 18607 14 &lt;BR /&gt;
14 18669 14&lt;BR /&gt;
14 18697 12;&lt;BR /&gt;
run;&lt;BR /&gt;
data test_output;&lt;BR /&gt;
set WORK.mytestdata;&lt;BR /&gt;
cnt=1;&lt;BR /&gt;
lag_acct = lag1(acct_nbr);&lt;BR /&gt;
lag_trans_date = lag1(trans_date);&lt;BR /&gt;
lag_amt = lag1(amt);&lt;BR /&gt;
do while &lt;BR /&gt;
(acct_nbr = lag_acct and trans_date-lag_trans_date &amp;lt;=50 and amt = lag_amt);&lt;BR /&gt;
cnt+1;&lt;BR /&gt;
end;&lt;BR /&gt;
run;

Message was edited by: scottp</description>
      <pubDate>Tue, 21 Jun 2011 21:19:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/incremental-counter-that-reset/m-p/18550#M2801</guid>
      <dc:creator>scottp</dc:creator>
      <dc:date>2011-06-21T21:19:43Z</dc:date>
    </item>
    <item>
      <title>Re: incremental counter that reset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/incremental-counter-that-reset/m-p/18551#M2802</link>
      <description>&amp;lt;=50 and amt = lag_amt);&lt;BR /&gt;
cnt+1;&lt;BR /&gt;
end;&lt;BR /&gt;
run;

Message was edited by: scottp</description>
      <pubDate>Tue, 21 Jun 2011 21:21:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/incremental-counter-that-reset/m-p/18551#M2802</guid>
      <dc:creator>scottp</dc:creator>
      <dc:date>2011-06-21T21:21:57Z</dc:date>
    </item>
    <item>
      <title>Re: incremental counter that reset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/incremental-counter-that-reset/m-p/18552#M2803</link>
      <description>Your pose is ambiguous.&lt;BR /&gt;
It is hard to understand what is your logic and what you want.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Wed, 22 Jun 2011 02:13:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/incremental-counter-that-reset/m-p/18552#M2803</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-06-22T02:13:27Z</dc:date>
    </item>
    <item>
      <title>Re: incremental counter that reset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/incremental-counter-that-reset/m-p/18553#M2804</link>
      <description>Scott,&lt;BR /&gt;
portions of your post were truncated.  your code may have included &amp;lt; or &amp;gt; signs.  Take a look at this link to see how to repost.&lt;BR /&gt;
&lt;A href="http://support.sas.com/forums/thread.jspa?messageID=27609毙" target="_blank"&gt;http://support.sas.com/forums/thread.jspa?messageID=27609毙&lt;/A&gt;</description>
      <pubDate>Wed, 22 Jun 2011 05:18:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/incremental-counter-that-reset/m-p/18553#M2804</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2011-06-22T05:18:56Z</dc:date>
    </item>
    <item>
      <title>Re: incremental counter that reset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/incremental-counter-that-reset/m-p/18554#M2805</link>
      <description>Scottp,&lt;BR /&gt;
I have made some changes to your code, and have come close to your requested output.  Please check your logic for the 6th data row.&lt;BR /&gt;
&lt;BR /&gt;
Notes:&lt;BR /&gt;
1) a semicolon in a datalines area signifies end of data (7th row)&lt;BR /&gt;
2) The DOWHILE was not needed and has been replaced with IF-THEN/ELSE&lt;BR /&gt;
[pre]data work.mytestdata;&lt;BR /&gt;
input acct_nbr  trans_date  amt;&lt;BR /&gt;
datalines;&lt;BR /&gt;
12 18638 20&lt;BR /&gt;
12 18669 17&lt;BR /&gt;
12 18711 17 &lt;BR /&gt;
14 18577 14&lt;BR /&gt;
14 18607 14 &lt;BR /&gt;
14 18669 14&lt;BR /&gt;
14 18697 12 &lt;BR /&gt;
run;&lt;BR /&gt;
data test_output;&lt;BR /&gt;
set WORK.mytestdata;&lt;BR /&gt;
lag_acct = lag1(acct_nbr);&lt;BR /&gt;
lag_trans_date = lag1(trans_date);&lt;BR /&gt;
lag_amt = lag1(amt);&lt;BR /&gt;
if(acct_nbr = lag_acct and trans_date-lag_trans_date le 50 and amt = lag_amt)then cnt+1;&lt;BR /&gt;
else cnt=1;&lt;BR /&gt;
run;&lt;BR /&gt;
title1 'cnt should be 1,1,2,1,2,3,1';&lt;BR /&gt;
proc print data=test_output;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt; hello,&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; I'm trying to create a counter that will reset when&lt;BR /&gt;
&amp;gt; criteria is met when comparing the previous record to&lt;BR /&gt;
&amp;gt; the current record. Please see my code below. for the&lt;BR /&gt;
&amp;gt; datalines (below)  the counter should the following&lt;BR /&gt;
&amp;gt; values: 1, 1,2,1,2,3,1. The counter should reset to&lt;BR /&gt;
&amp;gt; one if the prev acct number &amp;lt;&amp;gt; to the current record&lt;BR /&gt;
&amp;gt; account number + the current_date-previous_date &amp;gt; 50&lt;BR /&gt;
&amp;gt; + the current amt &amp;lt;&amp;gt; the prev amt. &lt;BR /&gt;
&amp;gt; Thank you for your help,&lt;BR /&gt;
&amp;gt; Scott&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; data work.mytestdata;&lt;BR /&gt;
&amp;gt; input acct_nbr $ trans_date $ amt;&lt;BR /&gt;
&amp;gt; datalines;&lt;BR /&gt;
&amp;gt; 12 18638 20&lt;BR /&gt;
&amp;gt; 12 18669 17&lt;BR /&gt;
&amp;gt; 12 18711 17 &lt;BR /&gt;
&amp;gt; 14 18577 14&lt;BR /&gt;
&amp;gt; 14 18607 14 &lt;BR /&gt;
&amp;gt; 14 18669 14&lt;BR /&gt;
&amp;gt; 14 18697 12;&lt;BR /&gt;
&amp;gt; run;&lt;BR /&gt;
&amp;gt; data test_output;&lt;BR /&gt;
&amp;gt; set WORK.mytestdata;&lt;BR /&gt;
&amp;gt; cnt=1;&lt;BR /&gt;
&amp;gt; lag_acct = lag1(acct_nbr);&lt;BR /&gt;
&amp;gt; lag_trans_date = lag1(trans_date);&lt;BR /&gt;
&amp;gt; lag_amt = lag1(amt);&lt;BR /&gt;
&amp;gt; do while &lt;BR /&gt;
&amp;gt; (acct_nbr = lag_acct and trans_date-lag_trans_date&lt;BR /&gt;
&amp;gt; &amp;lt;=50 and amt = lag_amt);&lt;BR /&gt;
&amp;gt; cnt+1;&lt;BR /&gt;
&amp;gt; end;&lt;BR /&gt;
&amp;gt; run;&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Message was edited by: scottp</description>
      <pubDate>Wed, 22 Jun 2011 05:34:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/incremental-counter-that-reset/m-p/18554#M2805</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2011-06-22T05:34:54Z</dc:date>
    </item>
  </channel>
</rss>

