BookmarkSubscribeRSS Feed
Manos
Calcite | Level 5

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

5 REPLIES 5
Haikuo
Onyx | Level 15

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

Manos
Calcite | Level 5

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
Haikuo
Onyx | Level 15

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

TomKari
Onyx | Level 15

Another option:

PROC MEANS DATA=have MEAN;

VAR return;

CLASS date;

FORMAT date MONNAME9.;

RUN;

Tom

Manos
Calcite | Level 5

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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 2670 views
  • 6 likes
  • 3 in conversation