Sample 49362: How to highlight significant p-values in PROC CORR output
Depending on the PROC CORR syntax, a PearsonCorr table is generated showing the following statistics:
- Correlation
- P-value
- Number of Observations
If changes are desired to any of the tables generated by PROC CORR or other procedures, the ODS TRACE ON statement can be used to determine which table template is being used. The table template can be edited with PROC TEMPLATE to adjust the results in the output destination(s). The
Full Code tab shows how to highlight significant p-values. In this example, values less than or equal to .05 are displayed in red in the resulting RTF file. This change takes effect by editing the Matrix2 column (p-value) in conjunction with a format created by PROC FORMAT. The style (color) change takes effect only in the non-Listing destinations.
The ODS TRACE ON information statement used in conjunction with this code is shown below:
ods trace on;
proc corr data=sashelp.iris;
var sepallength sepalwidth petallength petalwidth;
run;
The ODS TRACE ON statement generates the following information in the SAS log:
Output Added:
-------------
Name: PearsonCorr
Label: Pearson Correlations
Template: base.corr.StackedMatrix
Path: Corr.PearsonCorr
The Template name BASE.CORR.STACKEDMATRIX is used in the EDIT statement in PROC TEMPLATE to generate the desired changes.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
The sample code below creates an RTF file called Significance.rtf. The p-values whose values are less than or equal to .05 are displayed in red in the output file.
/* Add the WORK library to the ODS PATH */
ods path work.template(update) sashelp.tmplmst;
/*
The Matrix column is the correlation,
Matrix2 is the p-value,
Matrix3 is the number of observations contributing
Matrix4 is not used by the PearsonCorr table*
*With missing values in the data set, the COV option will produce a table with four rows, the 4th is Matrix4.
*/
proc format;
value pvalsig low-.05 ="red"
.05-high="black";
run;
proc template;
edit base.corr.stackedmatrix;
column (RowName RowLabel) (Matrix) * (Matrix2) * (Matrix3) * (Matrix4);
edit matrix2 ;
style={foreground=pvalsig.};
end;
end;
run;
title;
footnote;
/* Remove "The CORR Procedure" from the output */
ods noptitle;
ods trace on;
ods escapechar="^";
options orientation=portrait nodate nonumber;
/* Use the JOURNAL style, which has less table lines and uses the Arial font */
ods rtf file="significance.rtf" startpage=no style=journal;
/* Exclude all other libraries other than SASHELP.TMPLMST from the ODS PATH. */
/* This is used for demonstration purposes to show the default PROC CORR */
/* Pearsoncorr table's output. */
ods path sashelp.tmplmst;
ods text="^S={font_face=Arial font_size=11pt font_weight=bold outputwidth=100% just=c}Default output";
/* Just show the Pearsoncorr table*/
ods select pearsoncorr;
proc corr data=sashelp.iris;
var sepallength sepalwidth petallength petalwidth;
run;
ods text="^S={font_face=Arial font_size=11pt font_weight=bold outputwidth=100% just=c}Highlight significant Pvalues at the 95th Percentile";
/* Use the ODS PATH referenced above in order to pick up the changes created by PROC TEMPLATE */
ods path work.template(update) sashelp.tmplmst;
ods select pearsoncorr;
proc corr data=sashelp.iris;
var sepallength sepalwidth petallength petalwidth;
run;
ods _all_ close;
ods trace off;
/* Delete the edited BASE.CORR.STACKEDMATRIX table so the changes do no persist in later output tables */
proc template;
delete base.corr.stackedmatrix;
run;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
Click here to view the RTF output.
This sample illustrates how to highlight significant p-values in PROC CORR output.
Date Modified: | 2013-03-20 11:46:57 |
Date Created: | 2013-03-06 10:30:00 |
Operating System and Release Information
SAS System | SAS/STAT | z/OS | 9.2 TS1M0 | |
Microsoft® Windows® for 64-Bit Itanium-based Systems | 9.2 TS1M0 | |
Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9.2 TS1M0 | |
Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9.2 TS1M0 | |
Microsoft Windows XP 64-bit Edition | 9.2 TS1M0 | |
Microsoft® Windows® for x64 | 9.2 TS1M0 | |
Microsoft Windows Server 2003 Datacenter Edition | 9.2 TS1M0 | |
Microsoft Windows Server 2003 Enterprise Edition | 9.2 TS1M0 | |
Microsoft Windows Server 2003 Standard Edition | 9.2 TS1M0 | |
Microsoft Windows XP Professional | 9.2 TS1M0 | |
Windows Vista | 9.2 TS1M0 | |
Windows Vista for x64 | 9.2 TS1M0 | |
64-bit Enabled AIX | 9.2 TS1M0 | |
64-bit Enabled HP-UX | 9.2 TS1M0 | |
64-bit Enabled Solaris | 9.2 TS1M0 | |
HP-UX IPF | 9.2 TS1M0 | |
Linux | 9.2 TS1M0 | |
Linux for x64 | 9.2 TS1M0 | |
OpenVMS on HP Integrity | 9.2 TS1M0 | |
Solaris for x64 | 9.2 TS1M0 | |