BookmarkSubscribeRSS Feed
RL997
Calcite | Level 5

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.

 

1 REPLY 1
Ksharp
Super User

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;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

What is ANOVA?

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.

Discussion stats
  • 1 reply
  • 357 views
  • 0 likes
  • 2 in conversation