I want to rank a long list of records that contains groups and sub-groupings. The ranking would be based on each sub-group (e.g. 'Top 3 Products Purchased per Customer'). I think this should be fairly straight-forward but can't figure out how to do it. The data has three variables: Customer ID, Product Name, Number of Products Purchased. So for each unique customer id I need to sort and rank their top 3 products based on number of purchases.
Input:
Customer ID / Product / Num
12345 / Widget 1 / 999
12345 / Widget 2 / 750
12345 / Widget 3 / 500
12346 / Widget 1 / 99
12346 / Widget 4 / 25
12347 / Widget 4 / 56
12347 / Widget 5 / 25
Desired Output:Customer ID / Product / Num /
Rank12345 / Widget 1 / 999 /
112345 / Widget 2 / 750 /
212345 / Widget 3 / 500 /
312346 / Widget 1 / 99 /
112346 / Widget 4 / 25 /
212347 / Widget 4 / 56 /
112347 / Widget 5 / 25 /
2