Date: Thu, 8 Oct 2009 15:07:08 -0400
Reply-To: "Keintz, H. Mark" <mkeintz@WHARTON.UPENN.EDU>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Keintz, H. Mark" <mkeintz@WHARTON.UPENN.EDU>
Subject: Re: Calculating Returns by Stock
In-Reply-To: <9b88b90c-3f7e-412a-90ff-9a773f0b0c20@k41g2000vbt.googlegroups.com>
Content-Type: text/plain; charset="us-ascii"
B.Abbey:
The program below generates the cumulative returns, for each stock, at each time.
Data one (drop=lag_stock lag_price);
Infile cards;
input stock price;
retain cum_return;
lag_stock=lag(stock);
lag_price=lag(price);
if lag_stock^= stock then cum_return=0;
else cum_return= (1+cum_return) * (1 + (price-lag_price)/lag_price) - 1;
datalines;
1 11
1 12
1 10
1 21
1 13
2 21
2 19
2 25
RUN;
> -----Original Message-----
> From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
> B.Abbey
> Sent: Wednesday, October 07, 2009 10:42 PM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: Calculating Returns by Stock
>
> I need to calculate the returns for each specific stock. I am unsure
> how to approach this. The code is below but it calculates the returns
> for all of them. I need it to calculate the returns for stock 1 and
> then start over and calculate the returns for stock 2.
>
> DATA one ;
> INFILE cards ;
> INPUT stock price;
>
> CARDS;
>
> 1 11
> 1 12
> 1 10
> 1 21
> 1 13
> 2 21
> 2 19
> 2 25
> ;
> RUN;
>
> data two;
> set one;
> plag1 = LAG(price);
> return = (price - plag1) / plag1; // This calculates returns going
> straight down
> run; // I need it to
> calculate the final return for stock 1
> // then calculate
> returns for 2
|