how to convert daily data to weekly data

Reply
N/A
Posts: 1

how to convert daily data to weekly data

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.

example.png

This is how my data looks like. The data of observation is written as 19860101.

Super Contributor
Posts: 644

Re: how to convert daily data to weekly data

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

          then

               Do ;

                    Output ;

                    Weekly_Return = 1 ;

               End ;

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.

Richard

Ask a Question
Discussion stats
  • 1 reply
  • 1236 views
  • 0 likes
  • 2 in conversation