BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Cruise
Ammonite | Level 13

Hi Folks:

 

I'm trying to create a data of CORR and it's corresponding p-values from proc corr. Outp option outputs only CORR that I need but not p-value. 

Any suggestion as to how I could achieve the DESIRED OUTPUT below? Mock dataset attached to this post with two example variables and an outcome variable 'log_outcome'. I have many variables in actuality so that re-organizing in Excel sheet manually is not ideal.  

 

PROC CORR.png

 

proc corr data=have outp=outp;
var log_outcome houses rentals;
run;  
1 ACCEPTED SOLUTION

Accepted Solutions
ed_sas_member
Meteorite | Level 14

Hi @Cruise 

 

You can retrieve correlation coefficients as well as values by using 

ods output PearsonCorr=_PearsonCorr;

Here is the list of tables that you can output from PROC CORR (https://documentation.sas.com/?docsetId=procstat&docsetTarget=procstat_corr_details24.htm&docsetVers...)

Capture d’écran 2020-05-09 à 10.11.39.png

In your case, I would suggest something like this:

ods output PearsonCorr=_PearsonCorr;

proc corr data=have outp=outp pearson ;
	var houses rentals;
	with log_outcome;
run;  

/* Retrieve p-values */
proc transpose data=_PearsonCorr out=_pvalue(rename=(col1=pvalue)) name=_variables;
	var Phouses Prentals;
run;

data _pvalue2;
	set _pvalue;
	variables = substr(_variables,2);
	drop _:;
run;

/* Retrieve correlation coefficients */
proc transpose data=_PearsonCorr out=_corr(rename=(col1=corr)) name=variables;
	var houses rentals;
run;

/* Merge */
data want;
	length variables $ 20;
	merge _corr _pvalue2;
	by variables;
	label variables = "Variables"
	      corr = "Corr"
	      pvalue = "p-value";
run;

/* Report */
proc report data=want nowd;
	columns variables ("LOG_OUTCOME" corr pvalue);
run;

Best,

View solution in original post

2 REPLIES 2
WarrenKuhfeld
Ammonite | Level 13

Create an ODS output data set then use a DATA step to reformat the table to your liking.

ed_sas_member
Meteorite | Level 14

Hi @Cruise 

 

You can retrieve correlation coefficients as well as values by using 

ods output PearsonCorr=_PearsonCorr;

Here is the list of tables that you can output from PROC CORR (https://documentation.sas.com/?docsetId=procstat&docsetTarget=procstat_corr_details24.htm&docsetVers...)

Capture d’écran 2020-05-09 à 10.11.39.png

In your case, I would suggest something like this:

ods output PearsonCorr=_PearsonCorr;

proc corr data=have outp=outp pearson ;
	var houses rentals;
	with log_outcome;
run;  

/* Retrieve p-values */
proc transpose data=_PearsonCorr out=_pvalue(rename=(col1=pvalue)) name=_variables;
	var Phouses Prentals;
run;

data _pvalue2;
	set _pvalue;
	variables = substr(_variables,2);
	drop _:;
run;

/* Retrieve correlation coefficients */
proc transpose data=_PearsonCorr out=_corr(rename=(col1=corr)) name=variables;
	var houses rentals;
run;

/* Merge */
data want;
	length variables $ 20;
	merge _corr _pvalue2;
	by variables;
	label variables = "Variables"
	      corr = "Corr"
	      pvalue = "p-value";
run;

/* Report */
proc report data=want nowd;
	columns variables ("LOG_OUTCOME" corr pvalue);
run;

Best,

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 3883 views
  • 1 like
  • 3 in conversation