Solved
New Contributor
Posts: 4

# How do I get simple pearson correlations for 5 pairs and 8 groups

I am looking for a simple way to produce correlations for 5 pairs of variable across 8 groups.  I am using SAS 9.4 with  SAS/STAT 14.1 and can work on Enterprise Guide or Base SAS.

The code below is what I am using, thanks to others who have posted and appear in Lex Jansen's pages.

But my code produces 135 separate tabs when ods puts it in an excel file.

I tried doing all 10 in one proc corr statement, and that produced a 10 x 10 chart for each of the 8 groups.

I also don't need the 'Simple Statistics' table and am most interested in the correlation only.

Is there a way to get everything (all 5 pairs by 8 groups) into 1 table, or even 1 table for all 5 pairs for each of the 8 groups? I have to perform this with 9 databases, and am a lazy man, which is why I love SAS.

``````proc corr data = alltoclus;
var var1 var2;
run;

proc corr data = alltoclus;
var var3 var4;
run;

proc corr data = alltoclus;
var var5 var6;
run;

proc corr data = alltoclus;
var var7 var8;
run;

proc corr data = alltoclus;
var var9 var10 ;
run;``````

Accepted Solutions
Solution
‎04-18-2017 08:00 PM
Super User
Posts: 20,735

## Re: How do I get simple pearson correlations for 5 pairs and 8 groups

http://blogs.sas.com/content/iml/2015/05/26/suppress-ods.html

http://blogs.sas.com/content/iml/2017/01/09/ods-output-any-statistic.html

The above SAS blogs cover capturing and controlling output from a SAS Procedure.

Include all variables at once, store results in a dataset rather than use output and filter the dataset as desired.

All Replies
Solution
‎04-18-2017 08:00 PM
Super User
Posts: 20,735

## Re: How do I get simple pearson correlations for 5 pairs and 8 groups

http://blogs.sas.com/content/iml/2015/05/26/suppress-ods.html

http://blogs.sas.com/content/iml/2017/01/09/ods-output-any-statistic.html

The above SAS blogs cover capturing and controlling output from a SAS Procedure.

Include all variables at once, store results in a dataset rather than use output and filter the dataset as desired.

New Contributor
Posts: 4

## Re: How do I get simple pearson correlations for 5 pairs and 8 groups

Thank you!  That makes it easier.  I was able to run each pair once, and sort the outputby type and group in excel to get a simple chart of each pair by group. The revised code is below.

``````proc corr data = alltoclus outp=OutCorr1 NOPRINT;
var var1 var2;
run;

proc corr data = alltoclus outp=OutCorr2 NOPRINT;
var var3 var4;
run;

proc corr data = alltoclus outp=OutCorr3 NOPRINT;
var var5 var6;
run;
proc corr data = alltoclus outp=OutCorr4 NOPRINT;
var var7 var8;
run;

proc corr data = alltoclus outp=OutCorr5 NOPRINT;
var var9 var10 ;
run;``````
Super User
Posts: 10,213

## Re: How do I get simple pearson correlations for 5 pairs and 8 groups

```Do you like to use SAS/IML code ?

Post your sample data and the output .

```
New Contributor
Posts: 4

## Re: How do I get simple pearson correlations for 5 pairs and 8 groups

Thanks for asking, but the data is protected and would be difficult to mask so it could be posted.  I was able to use the links to the articles to find statements I could use to get the results I needed.

Super User
Posts: 20,735

## Re: How do I get simple pearson correlations for 5 pairs and 8 groups

SAMPLE data, it needs to show the structure of your data but doesn't have to be real.

☑ This topic is solved.