Help using Base SAS procedures

proc summary?

Reply
Contributor spg
Contributor
Posts: 61

proc summary?

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.


ID date product units cost($) trip
1 1/28/2005 2 1 20 1
1 2/3/2005 99 1 24 2
1 2/4/2007 9 1 24 3
1 4/13/2008 8 1 30 6
1 7/27/2008 8 1 30 7
1 11/9/2009 8 1 30 8
2 7/31/2005 7 1 25 1
2 3/20/2006 9 1 24 2
2 1/12/2007 9 1 14 3
2 2/6/2008 9 1 40 4
2 10/16/2009 9 1 19 5
3 3/24/2005 2,9 1,1 40 1
3 10/18/2006 4 3 45 2
3 5/6/2007 2 1 39 3
3 5/7/2007 99 1 39 4
3 4/17/2005 2,9 3,2 75,120 1
3 4/23/2005 7, 9 1,1 25,40 2
Super Contributor
Super Contributor
Posts: 3,174

Re: proc summary?

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.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search arguments, this topic/post:

data step processing site:sas.com

by group processing site:sas.com
Ask a Question
Discussion stats
  • 1 reply
  • 103 views
  • 0 likes
  • 2 in conversation