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
Question: How is your date variable constructed? Is it a SAS date (numeric variable) or just a char as "1925/01"?
Its numeric variable, (you are right, should specify that.)
dates | return |
19260130 | 0.023174 |
19260227 | -0.053510 |
19260331 | -0.096824 |
19260430 | 0.032946 |
19260528 | 0.001035 |
19260630 | 0.050487 |
19260731 | 0.013076 |
19260831 | 0.031002 |
19260930 | -0.006499 |
19261030 | -0.034630 |
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
Another option:
PROC MEANS DATA=have MEAN;
VAR return;
CLASS date;
FORMAT date MONNAME9.;
RUN;
Tom
Thank you both you have been really helpful, I managed to proceed!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.