Hello OzoneX15,
This is my understanding of your request (correct me if I am wrong):
[pre]
data i;
input tdate DDMMYY10. fund ISIN $ Price $ transmod $ NumberStocks;
format tdate date7.;
datalines;
19/02/2004 100174701 BE0003565737 47 buy 3000
19/03/2004 100174701 BE0003565737 44,8 buy 3800
24/03/2004 100174701 BE0003565737 44,59 buy 12050
23/06/2005 100174701 BE0003565737 66,65 buy 3900
11/11/2005 100174701 BE0003565737 73,15 buy 3000
14/11/2005 100174701 BE0003565737 73,2 buy 3800
17/05/2006 100174701 BE0003565737 84,3 buy 250
12/06/2006 100174701 BE0003565737 78,05 buy 800
11/08/2003 100174701 BE0003565737 87,85 sell 40000
11/08/2006 100174701 BE0003565737 87,85 sell 3800
21/09/2006 100174701 BE0003565737 84,75 buy 530
23/11/2006 100174701 BE0003565737 85,3 buy 30
4/12/2006 100174701 BE0003565737 85,95 buy 20
23/01/2007 100174701 BE0003565737 97,65 buy 260
13/02/2007 100174701 BE0003565737 97,8 sell 400
23/02/2007 100174701 BE0003565737 96,2 buy 150
6/03/2007 100174701 BE0003565737 89,67 sell 300
6/03/2007 100174701 BE0003565737 89,67 sell 40000
;
run;
proc sort data=i out=s;
by tdate fund ISIN;
run;
data t;
retain p;
set s;
if UPCASE(transmod)="SELL" and UPCASE(lag(transmod)) IN ("BUY","" ) then p+1;
if UPCASE(transmod)="BUY" and UPCASE(lag(transmod)) IN ("SELL","") then p+1;
by fund ISIN ;
run;
proc means data=t nway noprint;
output out=t1 (drop=_freq_ _type_) Sum=;
id tdate transmod;
class fund ISIN p;
var NumberStocks;
run;
data t2;
set t1;
if MOD(p,2)=0 then p1+1;
by fund ISIN;
run;
proc transpose data=t2 out=ts(drop=_name_);
id transmod;
var NumberStocks;
by fund ISIN p1;
run;
proc transpose data=t2 out=td(drop=_name_);
id transmod;
var tdate;
by fund ISIN p1;
run;
data r;
retain fund ISIN TDateSell StocksSell TDateBuy StocksBuy;
merge ts(rename=(Sell=StocksSell Buy=StocksBuy))
td(rename=(Sell=TDateSell Buy=TDateBuy));
by fund ISIN p1;
drop p1;
run;
[/pre]
Sincerely,
SPR
... View more