BookmarkSubscribeRSS Feed
kakahingwong
Calcite | Level 5

I have the following data, including mean, std and correlation matrix:

 

data test (type=corr);
input _type_$ _name_$ x1 x2 x3 x4 x5 x6 x7 x8;
datalines;
n . 176 176 176 176 176 176 176 176
mean . 608.65 59.09 0.8075 0.8553 40.75 7.697 94.55 42.56
std . 114.95 38.64 0.3776 0.3554 24.87 2.710 44.48 34.09
corr SP 1.0000 0.8383 0.6149 0.6837 0.7106 0.6891 0.6722 0.7046
corr EFB_POST 0.8383 1.0000 0.5739 0.7181 0.7893 0.7597 0.6851 0.9299
corr SPR 0.6149 0.5739 1.0000 0.6899 0.5478 0.5055 0.4975 0.5639
corr EFR 0.6837 0.7181 0.6899 1.0000 0.7120 0.7109 0.6172 0.6934
corr ECFA 0.7106 0.7893 0.5478 0.7120 1.0000 0.8105 0.7704 0.7546
corr HGC 0.6891 0.7597 0.5055 0.7109 0.8105 1.0000 0.7318 0.7413
corr NLT 0.6722 0.6851 0.4975 0.6172 0.7704 0.7318 1.0000 0.6736
corr EFB_PRE 0.7046 0.9299 0.5639 0.6934 0.7546 0.7413 0.6736 1.0000
;
run;

 

I've tried with the following command to find out the partial correlation, but the result doesn't look right to me.

 

proc proc corr data = test;
var x1 x2

partial x3 x4;
run;

 

Did I make any mistake there?  I am just looking for a better way other than using iml. Thanks in advance!

1 REPLY 1
FreelanceReinh
Jade | Level 19

Hello @kakahingwong and welcome to the SAS Support Communities!

 

So you want to compute partial correlations based on an existing correlation dataset. This is possible. However, it seems that PROC CORR doesn't like to process its own output datasets: You must have got the log message

 

WARNING: The input TYPE=CORR data set is treated as an ordinary SAS data set in proc CORR.

in addition to (as you noticed) nonsense results.

 

Luckily, there are other procedures which honor TYPE=CORR datasets as input. The documentation (TYPE=CORR Data Sets) mentions PROC REG among others. This is fortunate because PROC REG is capable of computing partial correlations: see this PharmaSUG 2010 paper.

 

First, I create a new correlation dataset from your dataset TEST with renamed variables because a TYPE=CORR dataset created with PROC CORR would contain the variables whose names are listed in variable _NAME_. Then I use PROC REG with the PCORR2 option of the MODEL statement (as suggested by the paper) to compute the square of the desired partial correlation coefficient and the corresponding p-value. Finally, I apply the SQRT function to obtain the partial correlation coefficient (variable PARTCORR).

data have(type=corr);
set test;
rename x1=SP x2=EFB_POST x3=SPR x4=EFR x5=ECFA x6=HGC x7=NLT x8=EFB_PRE;
run;

ods output ParameterEstimates=est;
proc reg data=have plots=none;
model SP=EFB_POST SPR EFR / pcorr2;
quit;

data want;
set est;
where dependent='SP' & variable='EFB_POST';
partcorr=sqrt(SqPartCorrTypeII);
keep dependent variable partcorr probt;
run;

proc print data=want;
run;

 

Here is another example using dataset FISH1 from the PROC CORR documentation: Example 2.6 Computing Cronbach’s Coefficient Alpha. I used this to compare the results from PROC REG (as above) to the results from PROC CORR with the PARTIAL statement (obtained from the original data rather than a TYPE=CORR dataset).

data fish1c;
set fish1;
if weight; /* remove an observation with a missing WEIGHT value */
run; /* 34 obs. */

ods output PartialPearsonCorr=ppc;
proc corr data=fish1c;
   var Height Width;
   partial Length3 Weight3;
run;

proc print data=ppc;
format _numeric_ best12.;
run;

proc corr data=fish1c outp=corrmat noprint;
   var Height Width Length3 Weight3;
run;

ods select none;
ods output ParameterEstimates=parest;
proc reg data=corrmat plots=none;
model Height=Width Length3 Weight3 / pcorr2;
quit;
ods select all;

data target;
set parest;
where dependent='Height' & variable='Width';
partcorr=sqrt(SqPartCorrTypeII);
keep dependent variable partcorr probt;
run;

proc print data=target;
format partcorr probt best12.;
run;

If you compare the two PROC PRINT outputs, you'll see that both the partial correlation coefficient and the corresponding p-value in dataset TARGET (obtained from the TYPE=CORR dataset using PROC REG) are equal (at least after rounding to 10 decimal places) to the results from PROC CORR in dataset PPC.

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

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