hello,
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 <> to the current record account number + the current_date-previous_date > 50 + the current amt <> the prev amt.
Thank you for your help,
Scott
data work.mytestdata;
input acct_nbr $ trans_date $ amt;
datalines;
12 18638 20
12 18669 17
12 18711 17
14 18577 14
14 18607 14
14 18669 14
14 18697 12;
run;
data test_output;
set WORK.mytestdata;
cnt=1;
lag_acct = lag1(acct_nbr);
lag_trans_date = lag1(trans_date);
lag_amt = lag1(amt);
do while
(acct_nbr = lag_acct and trans_date-lag_trans_date <=50 and amt = lag_amt);
cnt+1;
end;
run;
Message was edited by: scottp
... View more