02-18-2013 05:14 PM
I need to convert my daily stock data to weekly stock data. I want to calculate the weekly returns by compounding daily returns between adjacent Wednesdays.
This is how my data looks like. The data of observation is written as 19860101.
02-19-2013 08:26 AM
What does a retur of C signify? Tthis will have to be recoded as a numeric value.
Firstly you need to convert the date data into SAS date values (which you can then format to YYMMDDN8. so they still look the same as in your example (untested code) :
Date_of_observation = input(put(Date_of_observation,8.), DDMMYY8.) ;
Format Date_of_observation DDMMYYN8. ;
Compound the returns
Weekly_Return = Weekly_Return * return ;
Wednesday is Weekday 4 (Sunday = 1 for SAS) ; /* check the function name in SAS */
If Weekday(Date_of_observation) = 4
Weekly_Return = 1 ;
This will have to run inside another do loop to set Weekly_Return = 1 for the first day for each new company.
You might like to add code to discard results for incomplete weeks.