ARCHIVED: In SAS, how do I save a correlation or a covariance matrix as a data set?

This content has been archived, and is no longer maintained by Indiana University. Information here may no longer be accurate, and links may no longer be available or reliable.

In SAS, use the PROC CORR procedure to create a correlation or a covariance matrix and save it as a SAS data set.

For example, the following procedure would create a correlation matrix of the three variables age, response, and time, and save it as a data set named pearson_corr :

  PROC CORR DATA=drug OUTP=pearson_corr;
  VAR age response time;
  RUN;

Note: The OUTP option saves the Pearson correlation coefficients to a data set. If you need the Spearman correlation coefficients, use the OUTS option instead.

The data set specified with the OUTP or OUTS options will be saved to the SAS work directory.

For a covariance matrix, use the COV option in the PROC CORR statement:

  PROC CORR DATA=drug COV OUTP=corr_cov;
  VAR age response time;
  RUN;

The data set specified in the OUTP with COV option will include both correlation coefficients and covariances, the number of observations, means, standard deviations, and variable names.

If you have questions about using statistical and mathematical software at Indiana University, contact the UITS Research Applications and Deep Learning team.

This is document amrg in the Knowledge Base.
Last modified on 2023-05-09 14:44:22.