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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 383 views
  • 0 likes
  • 2 in conversation