UCLA Academic Technology Services HomeServicesClassesContactJobs
Help the Stat Consulting Group by giving a gift             
Loading

SAS Code Fragments
Computing Partial Correlation Via Regression

data test;
  input age x y ;
cards;
10 3 5
15 3 9
20 4 8
22 4 8
25 8 3
;
run;

* get partial correlation, it is -.94 ;
proc corr data=test;
  var x y ;
  partial age;
run;

* get residual for y , save in test2;
proc reg data=test;
  model y = age;
  output out=test2 r=yresid;
run;

* get residual for x (using test2), save in test3 ;
proc reg data=test2;
  model x = age;
  output out=test3 r=xresid;
run;

* show data ;
proc print data=test3;
run;

* do corr on "xresid" and "yresid" ;
* this works out to be -.94 ;
proc corr data=test3;
  var xresid yresid;
run;
* You can then plot "xresid" and "yresid" to ;
* see the relationship between x and y, after ;
* partialing out "age" ;

How to cite this page

Report an error on this page or leave a comment

UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services


The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California