Reputation: 3
I have a data as follows - Credit card transaction data
I need to add a counter variable for each credit card -- for each date and transaction country type. which should be look like this -Expected result with New counter variable
I am trying this with the help of by group (first. last.) but not getting expected result. Help needed for this problem statement. Thanks!!
Upvotes: 0
Views: 38
Reputation: 138
You are on the right track with applying the concepts first.
and last.
. Let me know if this works.
proc sort data=work.trans_data;
by cc_no dot country ts;
run;
data work.trans_data_cnt;
set work.trans_data;
by cc_no dot country ts;
/*This will assign the first row of the cc_no, dot, country = 1*/
if first.cc_no = 1 and first.dot = 1 and first.country = 1 then
counter = 1;
/*Restart counter, we have switched country, but are in the same cc_no and dot.*/
else if first.country = 1 then
counter = 1;
/*Increment the counter, we are within the same cc_no, dot, country.*/
else
counter + 1;
run;
Upvotes: 0