Help using Base SAS procedures

Data Set Transformation:Summary Data Set for Customer Purchase History

Reply
Frequent Contributor
Posts: 144

Data Set Transformation:Summary Data Set for Customer Purchase History

Hi. This is a tricky data set transformation.


I need to create a summary dataset/report which tracks the flow of these purchases over time.

I have a dataset which gives a signup date for an overall service and 9 variables which give the purchase dates for different add on products.  If the add on variable dates match the signup date then those add on products were included with the signup package.  Any add on variable purchase date that comes after the signup date are products which are purchased during the history of the active account.  This is what it looks like:

IDsignup_DTpreferredhd_tv_estbd_dtultimate_estbd_dtquant_estbd_dtFullyLoaded_estbd_dtHB_estbd_dtCin_estbd_dttime_estbd_dtrouter_estbd_dtinternet_estbd_dt
986636994/7/144/9/144/7/149/12/1410/15/14.4/7/144/7/144/12/14.
336637984/11/14.4/11/14.4/11/144/11/144/11/144/11/146/11/147/15/14
436634635/12/145/12/145/12/149/5/149/17/14.....
776614375/16/14.5/16/14.10/31/14.5/16/145/16/1411/16/14.
856622955/29/14..5/29/14.6/12/14..11/16/14.
366567566/4/14...6/4/146/4/146/12/146/4/146/4/1412/4/14
676626466/14/14.6/14/148/31/14..6/17/146/14/14.6/22/14
556637866/26/14...8/14/146/26/147/8/146/26/1411/30/14.
446631918/21/14.9/30/14....1/12/15.10/31/14

The variables I’m trying to produce are:

  1. Signup month (easy to do)
  2. A count of the total number of signups for that month (easy to do)
  3. A overall count of additional products which  included with sign up
  4. A variable which has all add on product values (transposed from original dataset).
  5. A count of the different products purchased on the startup date
  6. A count of add on products purchased after the signup date that were purchased in the same month of the signup date
  7. Then month variables which count the additional add on products by mont

If I take just April, this is the output I'm looking for:

Sign_up_MonthSign_up_count Initial_Products_totalProductsProd_Purchased_on_SignupAddPro_ April_After_SU May JuneJuly AugustSeptember October
April28preferredhd_tv_estbd_dt1
April28ultimate_estbd_dt2
April28quant_estbd_dt1
April28FullyLoaded_estbd_dt11
April28HB_estbd_dt1
April28Cin_estbd_dt2
April28time_estbd_dt2
April28router_estbd_dt11
April28internet_estbd_dt1

I have attached an excel workbook with an example of the full output and the mock data set.

I having been messing with arrays to try and accomplish this  but I've been having trouble. Any assistance is greatly appreciated.

Attachment
Frequent Contributor
Posts: 144

Re: Data Set Transformation:Summary Data Set for Customer Purchase History

I forgot to include the code I have which produces the first three vars: signup_month, Sign_up_count, Initial_Products_total

proc sort data=have;

by ID signup_DT; run;

proc transpose data=have out=have(drop=_LABEL_);

by ID signup_DT; run;

data have;

set have;

if signup_DT=COL1 then Initialprod_flag=1;run;

proc sql;

create table have as

select  distinct

count( distinct ACCT_SK) as Sign_up_count ,

month (signup_DT) as signup_month,

sum (Initialprod) as Initial_Products_total

from have

group by month (signup_DT) ; quit;

Ask a Question
Discussion stats
  • 1 reply
  • 179 views
  • 0 likes
  • 1 in conversation