我正在尝试结合我的算法来计算新价格,具体取决于滚动周时间段和阈值促销百分比。我需要帮助来解密很久以前用SAS编写的旧代码。
基本价格为“ MSRP”或每日价格。我每周都有商品的“平均售价”。这需要删除异常值,并使用统计信息根据您预定的时间段和促销百分比阈值来计算BP。例如,如果discount = abs((ASP / BasePrice)-1),并且Discount <=促销百分比阈值(即20%),则交易标志=否则为0。真正的问题是正确计算%ondeal。这是=交易标志/ SKU计数。 SKUcount =按星期模型组存储和另一个变量计数不同的项目。
%macro baseprice(indsn,outdsn,Bpfile,item,time,endwk,disc);
proc sort data=&indsn;
by &item &time;
run;
proc means noprint data=&indsn;
by &item &time;
output out=basemode
mode(ASP)=modeprice
median(ASP)=medianprice
;
run;
data baseprice;
set basemode;
if modeprice ne . then ASP=modeprice;
else if modeprice=. then ASP=medianprice;
keep &item &time ASP;
run;
proc sort data=baseprice;
by &item &time;
run;
data basesum2 (keep=&item baseprice ASP counter compwk &time sumprice); ;
set baseprice;
by &item;
retain baseprice realprice counter sumprice compwk;
if first.&item then do;
baseprice=ASP;
realprice=ASP;
counter=0;
sumprice=0;
compwk=&time;
output;
end;
else if &time < compwk+12 then do;
if abs((ASP/baseprice) - 1) > .05 then do;
sumprice=sumprice+ASP;
counter=counter+1;
if counter=7 then do; /* has to do with price and promo */
baseprice=sumprice/counter;
output;
counter=0;
compwk=&time;
sumprice=0;
end;
end;
else do;
counter=0;
sumprice=0;
compwk=&time;
end;
end;
else if &time >= compwk+12 then do;
counter=0;
sumprice=0;
compwk=&time;
end;
run;
data basesum2;
set basesum2;
by &item;
retain fweek bprice;
if first.&item then do;
fweek=&time;
bprice=baseprice;
end;
else do;
eweek=&time-1;
output;
fweek=&time;
bprice=baseprice;
end;
if last.&item then do;
fweek=&time;
bprice=baseprice;
eweek=&endwk ;
output;
end;
run;
data &bpfile;
set basesum2;
do &time=fweek to eweek;
bprice=round(bprice,.01);
output;
end;
keep &item &time bprice;
run;
proc sort data=&indsn;
by &item &time;
run;
proc sort data=&bpfile;
by &item &time;
run;
data &outdsn (drop=bprice discount);
merge &indsn (in=a) &bpfile (in=b);
by &item &time;
if a and b;
discount=((ASP-bprice)/bprice)*100;
if discount <= &disc then deal=1;
else deal=0;
run;
%mend;
%macro tranit(indsn,outdsn,type);
data &indsn;
set &indsn;
PercOnDeal=(Deal/SKUCount)*100;
FragIndex=(Brands/SKUCount)*100;
run;
proc transpose data=&indsn out=tran;
by ppweek &type;
run;
proc transpose data=tran out=&outdsn (drop=_NAME_);
by ppweek;
id &type _NAME_ ;
var COL1;
run;
%mend;
%baseprice(step_2_1, step_3, step_3_BP, itemnumber_unsuppressed, ppweek,
2570, -20);