钢鞭男来了,快闪!作者: shiyiming 时间: 2009-8-7 16:17 标题: Re: 再问下“死猪头” :D 老夫来凑个热闹
[code:3bxnwdd4]data store(keep=id date orinum num) sellandgift(keep=id date num act note);
input ID$ Date yymmdd8. Num Act Note ;
if act=1 then oriNum=Num;
format Date yymmdd10.;
if act=1 and note=. then output store;
else output sellandgift;
datalines;
001 08-07-01 100 1 .
001 08-07-02 20 0 .
001 08-07-05 100 1 .
001 08-07-06 80 0 .
001 08-07-07 40 0 .
001 08-07-08 40 0 .
001 08-07-09 100 1 .
001 08-07-10 120 1 0
001 08-07-12 240 0 .
002 08-07-01 100 1 .
002 08-07-02 20 0 .
002 08-07-05 80 0 .
002 08-07-06 100 1 .
002 08-07-08 50 0.
;
run;
%let offsetid=0;
data allavg;
length id $8 Orinum num date offnum diff 8;
run;
%macro updateStore(num,note,id,selldate) ;
%let offsetid=%eval(&offsetid+1);
%if &note eq %then
%do;
data store(keep=id date num orinum ) avg(keep=id date OriNum offnum num diff);
left=0;
set store ;
by id date;
retain number &num ;
if id=&id then do;
offnum=min(num,number);
num=num-offnum;
number=number-offnum;
diff=(&selldate-date);
end;
if offnum>0 then output avg;
if num>0 then output store;
run;
proc append base=allavg
data=avg force;
run;
%end;
%if &note=0 %then
%do;
proc sql;
create table store(drop=oldnum ) as
select *,oldnum+oldnum/sum(oldnum)*&num*(id="&id") as num
from store(rename=(num=oldnum ))
group by id
order by id,date;
%end;
%mend;
data _null_;
set sellandgift;
call execute('%updateStore('||num||','||note||','||id||','||date||')');
run;
proc sql;
create table final as
select distinct id, date format=yymmdd10., oriNum,sum(diff*offnum)/sum(offnum) as avgdiff
from allavg
group by id,date
having min(num)=0
order by id,date;
[/code:3bxnwdd4]作者: shiyiming 时间: 2009-8-7 20:11 标题: Re: 再问下“死猪头” :D 谢谢死猪头啊 <!-- s:D --><img src="{SMILIES_PATH}/icon_biggrin.gif" alt=":D" title="Very Happy" /><!-- s:D --> <!-- s:D --><img src="{SMILIES_PATH}/icon_biggrin.gif" alt=":D" title="Very Happy" /><!-- s:D -->
你的程序怎么不见了??作者: shiyiming 时间: 2009-8-7 20:13 标题: Re: 再问下“死猪头” :D to ahuige
if act=0 then do;
t=num;
i=StckNo-1;
do while(i>=0);
u=stock{i};
stock{i}=max(stock{i}-t,0);
t=t-u;
put i=;
if stock{i}=0 then StckNo=StckNo-1;
if stock{i}<u then do;
lsting=datdif(dt{i},date,'act/act');
sell=u-stock{i};
InStckDt=dt{i};
output c;
end;
if stock{i}=0 then dt{i}=0;
if t=0 then return;
i=i-1;
end;
end;
format InStckDt yymmdd10.;
run;
[/code:2c4ajr1l]