Programming the statistical procedures from SAS

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

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

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;
by Grade;
run;

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

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

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

proc corr data = alltoclus;
var var9 var10 ;
by Grade;
run;

 


Accepted Solutions
Solution
‎04-18-2017 08:00 PM
Grand Advisor
Posts: 16,926

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. 

View solution in original post


All Replies
Solution
‎04-18-2017 08:00 PM
Grand Advisor
Posts: 16,926

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: 3

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;
by Grade;
run;

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

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

proc corr data = alltoclus outp=OutCorr5 NOPRINT;
var var9 var10 ;
by Grade;
run;
Grand Advisor
Posts: 9,466

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: 3

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.

Grand Advisor
Posts: 16,926

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.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 108 views
  • 2 likes
  • 3 in conversation