Hi, I've look at at least 12 similar posts with out getting it right. I hope someone can solve this one!
The below code is a preparation for a rolling 12 months total active customer count, that keeps rolling over they years. What code should I use to continue and get:
* IMPORTANT: For each 12 months period, the same cust_id can only be counted once.
* I want as the table below (but with the above statement in mind)
data orders;
set order_info;
keep brand cust_id country monthyear value;
monthyear = intnx('month',t_dat,0,"BEGINNING");
format monthyear date9.;
value=1;
run;
proc sort data=orders nodupkey;
by brand country cust_id monthyear;
run;
data customers;
set customer_info;
keep brand cust_id email country;
run;
proc sort data=customers nodupkey;
by brand email cust_id country;
run;
data merge_orders_customers;
merge orders (in=a) customers (in=b);
by brand cust_id country;
if a and b;
run;
proc sort data=merge_orders_customers;
by brand email country descending monthyear;
run;
proc sort data=merge_orders_customers nodupkey;
by brand email country;
run;
proc means data=merge_orders_customers noprint;
output out = total sum=;
by brand country monthyear;
run;
Brand
Country
monthyear
value
rolling12
BrandA
GB
01-dec-17
4337
4337
BrandA
GB
01-jan-18
3995
8332
BrandA
GB
01-feb-18
1953
10285
BrandA
GB
01-mar-18
2961
13246
BrandA
GB
01-apr-18
2728
15974
BrandA
GB
01-maj-18
3586
19560
BrandA
GB
01-jun-18
5167
24727
BrandA
GB
01-jul-18
4676
29403
BrandA
GB
01-aug-18
3610
33013
BrandA
GB
01-sep-18
4545
37558
BrandA
GB
01-okt-18
6114
43672
BrandA
GB
01-nov-18
6403
50075
BrandA
GB
01-dec-18
10531
56269
BrandA
GB
01-jan-19
7655
59929
BrandA
GB
01-feb-19
5435
63411
BrandA
GB
01-mar-19
8170
68620
BrandA
GB
01-apr-19
7786
73678
BrandA
GB
01-maj-19
8205
78297
BrandA
GB
01-jun-19
12129
85259
BrandA
GB
01-jul-19
11270
91853
BrandA
GB
01-aug-19
8494
96737
BrandA
GB
01-sep-19
10344
102536
BrandA
GB
01-okt-19
21546
117968
BrandA
GB
01-nov-19
14789
126354
BrandA
GB
01-dec-19
26496
142319
BrandA
GB
01-jan-20
20308
154972
BrandA
GB
01-feb-20
14091
163628
BrandA
GB
01-mar-20
22798
178256
BrandA
GB
01-apr-20
33769
204239
BrandA
GB
01-maj-20
34623
230657
BrandA
GB
01-jun-20
41845
260373
BrandA
GB
01-jul-20
35616
284719
BrandA
GB
01-aug-20
30437
306662
BrandA
GB
01-sep-20
52758
349076
BrandA
GB
01-okt-20
72768
400298
... View more