有这样一个数据集test,是某零售商关于顾客购买记录以及商品维修记录: orderID customerID price purchase_brand buy_date repair_date
1 001 1253 西门子 2005/10/05 .
2 002 1745 dell 2001/10/05 2012/11/04
3 003 4598 小米 2002/10/05 2011/01/03
4 003 321 海信 2004/10/05 .
5 004 546 海尔 2003/10/05 2015/05/01
6 005 2154 海信 2001/10/05 .
7 006 999 海尔 2005/10/05 2013/10/25 我用后面的程序计算:(1)有维修记录的顾客在维修日期之后的购买记录的次数,以及在维修日期之后购买的总金额 ; (2)有维修记录的顾客在第一次维修日期之后的购买同一品牌(与第一次维修时的品牌相同)的次数,以及在维修日期之后购买同一品牌的总金额。
现在的问题是:计算出有的顾客购买同一品牌的次数大于其购买次数,按理来说购买同一品牌的次数应该小于等于其购买次数的,请问这是什么原因呢。这种情况占了样本量百分之一左右。请大神帮忙看看是哪里不对。 程序如下: proc sortdata=test;
by customerID descending repair_date;
run;
data test1;
set test;
by customerID descending repair_date;
retain purchase_times sum_price repair_date_temp;
if first.customerID then
do;
purchase_times=0;
sum_price=0;
repair_date_temp=repair_date;
end;
if not missing(repair_date_temp) andbuy_date>repair_date_temp then
do;
purchase_times+1;
sum_price+price;
end;
if last.customerID;
run;
proc sort data=test;
by customerID purchase_brand descendingrepair_date;
run;
/*(2)有维修记录的顾客在维修日期之后的购买同一品牌的次数,以及在维修日期之后购买同一品牌的总金额。*/
data test2;
set test;
by customerID purchase_brand descendingrepair_date;
retain purchase_times sum_price repair_date_temp;
if first. customerID and first.purchase_brandthen
do;
purchase_times=0;
sum_price=0;
repair_date_temp=repair_date;
end;
if not missing(repair_date_temp) andbuy_date>repair_date_temp then
do;
purchase_times+1;
sum_price+price;
end;
if last. customerID and last.purchase_brand;
run;
|