Hi try this code it may help you , proc sort data=test out=temp1; by customer_id month_num; run; data temp2; retain mon; set temp1; by customer_id month_num; if(first.customer_id = 1 and last.customer_id = 0) then do; mon=month_num; output; end; if (first.customer_id = 0 and last.customer_id = 0) then do; if mon=(month_num-1) then output; mon=month_num; end; if (first.customer_id = 0 and last.customer_id = 1) then do; if mon=(month_num-1) then output; end; run; proc sql; create table answer as select customer_id ,Month , Month_num ,Product from temp2 group by customer_id having count(customer_id)>=3 order by customer_id, month_num; quit;
... View more