Hi, I have a .sas file containing monthly returns. In order to get annual returns, I am trying to write a SAS code, which takes each monthly return of each given year, adds 1 and multiplies them together. For instance, if there are monthly returns from March- Dec, March 2008 +5% April 2008 -7% etc Dec 2008 +2% Jan 2009 +3% etc. Dec 2009 -2% the calculation should look like (1.05*0.93*...*1.02) for 2008, and (1.03*...*0.98) for 2009 I have many different stocks, which are all identified by a PERMNO number unique to that stock, and stock returns from 1998-2013. After the calculation, SAS should return the annual cumulative return and copy it into a separate database, i.e. the resulting output database should look like this: Permno Year Cumulative return 10104 2008 1.035 2009 1.015 11038 1998 1.01 1999 1.005 2000 1.08 I have written the SAS code below, but for some reason, it doesn't work as intended. I have tried quite a few workarounds, but unfortunately, wasn't successful. ------------------------------------------------------------------------------------------------------------------------------------- data ReturnsSAS; set cleandat.ReturnSAS; n year=year(date); month=month(date); proc sql; create table cum_returns as select permno , product(1+ret) as cum_return , min(ret) as minret , max(ret) as maxret , n(ret) as n_periods , nmiss(ret) as n_miss , sum(ret=.P) as n_dot_p , min(date) as first_date , max(date) as last_date from ReturnsSAS where ('01jan1998'd <= date <= '31dec2013'd); quit; print data=ReturnsSAS.cum_returns; format first_date last_date yymmdd10.; run; ------------------------------------------------------------------------------------------------------------------ Many thanks for your help, Amatron
... View more