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:
ID | signup_DT | preferredhd_tv_estbd_dt | ultimate_estbd_dt | quant_estbd_dt | FullyLoaded_estbd_dt | HB_estbd_dt | Cin_estbd_dt | time_estbd_dt | router_estbd_dt | internet_estbd_dt |
98663699 | 4/7/14 | 4/9/14 | 4/7/14 | 9/12/14 | 10/15/14 | . | 4/7/14 | 4/7/14 | 4/12/14 | . |
33663798 | 4/11/14 | . | 4/11/14 | . | 4/11/14 | 4/11/14 | 4/11/14 | 4/11/14 | 6/11/14 | 7/15/14 |
43663463 | 5/12/14 | 5/12/14 | 5/12/14 | 9/5/14 | 9/17/14 | . | . | . | . | . |
77661437 | 5/16/14 | . | 5/16/14 | . | 10/31/14 | . | 5/16/14 | 5/16/14 | 11/16/14 | . |
85662295 | 5/29/14 | . | . | 5/29/14 | . | 6/12/14 | . | . | 11/16/14 | . |
36656756 | 6/4/14 | . | . | . | 6/4/14 | 6/4/14 | 6/12/14 | 6/4/14 | 6/4/14 | 12/4/14 |
67662646 | 6/14/14 | . | 6/14/14 | 8/31/14 | . | . | 6/17/14 | 6/14/14 | . | 6/22/14 |
55663786 | 6/26/14 | . | . | . | 8/14/14 | 6/26/14 | 7/8/14 | 6/26/14 | 11/30/14 | . |
44663191 | 8/21/14 | . | 9/30/14 | . | . | . | . | 1/12/15 | . | 10/31/14 |
The variables I’m trying to produce are:
If I take just April, this is the output I'm looking for:
Sign_up_Month | Sign_up_count | Initial_Products_total | Products | Prod_Purchased_on_Signup | AddPro_ April_After_SU | May | June | July | August | September | October |
April | 2 | 8 | preferredhd_tv_estbd_dt | 1 | |||||||
April | 2 | 8 | ultimate_estbd_dt | 2 | |||||||
April | 2 | 8 | quant_estbd_dt | 1 | |||||||
April | 2 | 8 | FullyLoaded_estbd_dt | 1 | 1 | ||||||
April | 2 | 8 | HB_estbd_dt | 1 | |||||||
April | 2 | 8 | Cin_estbd_dt | 2 | |||||||
April | 2 | 8 | time_estbd_dt | 2 | |||||||
April | 2 | 8 | router_estbd_dt | 1 | 1 | ||||||
April | 2 | 8 | internet_estbd_dt | 1 |
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.
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;
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.