DATA Step, Macro, Functions and more

Monthly average returns

Reply
New Contributor
Posts: 3

Monthly average returns

Hi to all,

I am new in SAS and I really would appreciate your help in how to continue with my data.

I have monthly average returns of an index for 20 years in two columns the one is the date column with the additional month and the other column is the return for the month.

So now my data is something like this:

date             return

1925/01        2,34

1925/02        3,76

1925/03        2,69

This keeps going until 12/1945. However I care about the average return of each month (January, February,..., December) for the whole period of the 20 years. So i want to transform my data in this form.

Month    Average Monthly return 1925-1945

Jan              2,98

Feb             3,67

March          3,29

Jun              2,43

Jul              .....

Aug            .....

Sept            .....

Οct            ......

Nov           .....

Dec           2,86

So i want know the average return individually for each for this period. I hope I am clear in what I am asking.

Thank you in advance

Respected Advisor
Posts: 3,156

Re: Monthly average returns

Question: How is your date variable constructed? Is it a SAS date (numeric variable) or just a char as "1925/01"?

New Contributor
Posts: 3

Re: Monthly average returns

Its numeric variable, (you are right, should specify that.)

datesreturn
192601300.023174
19260227-0.053510
19260331-0.096824
192604300.032946
192605280.001035
192606300.050487
192607310.013076
192608310.031002
19260930-0.006499
19261030-0.034630
Respected Advisor
Posts: 3,156

Re: Monthly average returns

This hopefully can get you started:

proc sql;

  create table want as

  select put(input(put(dates,8.),yymmdd8.),monname3.) as month, mean(return) as Average_1925_1945 from have

  group by month

;quit;

Haikuo

PROC Star
Posts: 1,167

Re: Monthly average returns

Another option:

PROC MEANS DATA=have MEAN;

VAR return;

CLASS date;

FORMAT date MONNAME9.;

RUN;

Tom

New Contributor
Posts: 3

Re: Monthly average returns

Thank you both you have been really helpful, I managed to proceed!

Ask a Question
Discussion stats
  • 5 replies
  • 510 views
  • 6 likes
  • 3 in conversation