I have a dataset that looks like the one below. The date column is sorted. I’m trying to create a table which will summarize
• If the “first” purchase in 2005 is product ‘2’ and then
• How many units of products 7 & 9 were bought by the person (ID) over the following years
I tried using Proc Summary. The problem is that there are multiple cases in which the person bought products 2 along with something else on their first purchase in 2005 (hence the multiple units & cost entries in certain rows). I have put them with commas to make a distinction. However, my dataset has them in the same box and separated by a space.
You will want to consider using a DATA step and with a sorted input file look to using BY group processing. You can accumulate (SUM function to a new "total" variable) observations that meet your data criteria. The BY group processing takes a list of BY group variables and also a "break" variable -- you will be using IF / THEN ; statements in your DATA step to do the numeric variable aggregation.
The BY group processing topic is discussed in the SAS DOC - suggest doing a Google search to find suitable reference material on the SAS support website.
Suggested Google advanced search arguments, this topic/post: