I have a set of data organized like this:
ID Date Return
A 1/1/2001 .01
A 2/1/2001 .005
.. … …
A 12/1/2001 -.001
B 1/1/2001 .009
B 2/1/2001 .015
… … …
B 12/1/2001 -.005
C 1/1/2001 .007
C 2/1/2001 .005
.. … …
C 12/1/2001 .002
I would like my output to show a matrix of ‘Return’ correlations along with p-values
A B C
A 1.00 .778 .562
(p val) (p val) (p val)
B .778 1.00 .342
(p val) (p val) (p val)
C .562 .342 1.00
(p val) (p val) (p val)
I can’t figure out how to do this with proc corr. The code I tried was this:
proc corr data = ReturnsByID;
var return;
by id;
ods output pearsonCorr = RetCorrMat;
run;
Any suggestions?
Thanks.
Then Change your data structure to fit the PROC CORR .
data have;
input ID $ Date : mmddyy10. Return;
format date mmddyy10.;
cards;
A 1/1/2001 .01
A 2/1/2001 .005
A 12/1/2001 -.001
B 1/1/2001 .009
B 2/1/2001 .015
B 12/1/2001 -.005
C 1/1/2001 .007
C 2/1/2001 .005
C 12/1/2001 .002
;
proc sort data=have out=temp;
by date;
run;
proc transpose data=temp out=want;
by date;
var return;
id id;
run;
proc corr data=want;
var a b c;
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.