Help with Pearson Corrrelation coefficients and probabilities

Reply
New Contributor
Posts: 2

Help with Pearson Corrrelation coefficients and probabilities

 

I need the pearson correlation coefficents and respective probabilities for the
independent variables of a regression in a nice table (like dataset3 below).
First for one regression, then I'll be adding more regressions to the dataset
(dataset3 below).

 


First I ran this code to get the output in dataset1

ods output PearsonCorr=dataset1;
proc corr data=originaldata;
run;


dataset1       

Variable     Label    x1       x2        y         PX1    PX2    PY
X1                         1.00     0.25    0.10      _      0.23   0.26
X2                          0.25    1.00   -0.14    0.23    _      0.20
Y                    Y      0.10   -0.14   1.00     0.26   0.20      _    
       
             
It has more columns/values than I need, so
modified above data with below code to get dataset2


data pearsoncorrelations2;
set dataset1;
if Variable = "Y" then output;
run; 
      
dataset2       
       
Variable  Label    X1       X2    Y    PX      PX2   PY
Y                Y      0.10  -  0.14  1    0.26     0.20   _   
       
       
But now I need
the data in the following format, but how do i do that? I also
don't need the Label and PY columns.

 

dataset3       
       
Variable     pearsoncoefs PROB     
X1                0.10              0.26     
X2               -0.14              0.20

 

Thanks in advance!

PROC Star
Posts: 831

Re: Help with Pearson Corrrelation coefficients and probabilities

[ Edited ]

data want;

set have;

pearsoncoefs =x1;

PROB    =PX1     ;

variable=vname(x1);

output;

pearsoncoefs =x2;

PROB    =PX2      ;

variable=vname(x2);

output;

keep Variable     pearsoncoefs PROB ;

run;

Super User
Posts: 21,546

Re: Help with Pearson Corrrelation coefficients and probabilities

Try PROC TRANSPOSE if you need a dynamic option. If you need just for your example data, then @novinosrin code is suitable. 

 

You would like need a double transpose, once to a wide format and once to the desired format.

New Contributor
Posts: 2

Re: Help with Pearson Corrrelation coefficients and probabilities

Thanks both for your quick responses. It works now but as you can imagine I don't want to

have to manually type in the name of the variables as for some regressions there might be more than 2 variables. Is there a way to do that? I was looking into the syntax for the "%do loop in SAS but it didn't look like it works for this case (variable names).

 

 

PROC Star
Posts: 831

Re: Help with Pearson Corrrelation coefficients and probabilities

Try proc transpose as suggested by Reeza

Ask a Question
Discussion stats
  • 4 replies
  • 106 views
  • 1 like
  • 3 in conversation