/* step 1 - importing the data into sas */ filename trans CSV 'C:\ ...path to and file name... .CSV'; data trans; infile trans dlm=',' truncover; input TRANSACTION_ID TRANSACTION_VALUE USER MONTH YEAR ; transaction_month = mdy(month, 01, year); /* create a date variable */ run; /* step 2 - summarizing */ proc sql; create table tr_sum as select user, transaction_month sum(transaction_value) as tr_sum from trans group by user, transaction_month order by user, transaction_month descending; quit; /* step 3 - calculating the flag */ data tr_flag; set tr_sum; by user transaction_month descending; if first.user then flag=0; else if tr_sum > lag(tr_sum) then flag = 1; else flag=0; run; /* step 4 - merging the flag in the original dataset */ proc sql; create table trans_new as select t.*, s.flag from trans as t left join tr_sum as s on t.user = s.user and t.transaction_month = s.transaction_month order by TRANSACTION_ID, USER, year, MONTH; /* adapt it to your needs */ quit;
... View more