Hi, If you want to find the out how many times a particular customer is moving to different retailer for different products and for specific time interval, then you need to include all possible mevements...Here in sample data, there are 3 retailers so you need to find out following: How Many times customer is moving from WALLMART to BESTBUY for different products How Many times customer is moving from WALLMART to FRYS for different products How Many times customer is moving from BESTBUY to FRYS for different products Here is my try, don't know it meets your requirement...But based on the business logic you mentioned in your very first post, i prepered the SAS Code as follow: proc sql; create table want as select a.consumer_id,a.retailer as from_retailer, b.retailer as to_retailer,a.product_code, a.shopping_date as from_date,b.shopping_date as to_date, count(a.consumer_id) as FP from have as a,have as b where a.Consumer_ID = b.Consumer_ID group by 1,2,3,4,5,6; quit; data want; set want; if from_retailer = to_retailer or from_date GT to_date then delete; run; proc sort data = want; by from_retailer to_retailer FP; run; data want; set want; by from_retailer to_retailer FP; if last.from_retailer or last.to_retailer and last.FP then output; run; proc sort data = want(drop = product_code); by from_date to_date FP; run; -Urvish
... View more