Table of Contents
SAS is a statistical software that allows users to calculate correlations between variables. To calculate the correlation in SAS, one can use the PROC CORR procedure. This procedure generates a correlation matrix that displays the relationships between all selected variables. Users can also specify the type of correlation coefficient they want to calculate, such as Pearson’s or Spearman’s. Additionally, SAS allows for the inclusion of categorical variables in the correlation analysis. For example, one can calculate the correlation between income and education level, while also considering gender as a categorical variable. Overall, SAS provides a flexible and robust method for calculating correlations and can be utilized for various research and data analysis purposes.
Calculate Correlation in SAS (With Examples)
One way to quantify the relationship between two variables is to use the , which measures the linear association between two variables.
It always takes on a value between -1 and 1 where:
- -1 indicates a perfectly negative linear correlation between two variables
- 0 indicates no linear correlation between two variables
- 1 indicates a perfectly positive linear correlation between two variables
The further away the correlation coefficient is from zero, the stronger the relationship between the two variables.
The following examples show how to use proc corr in SAS to calculate the correlation coefficient between variables in the SAS built-in dataset called , which contains various measurements for 159 different fish caught in a lake in Finland.
We can use proc print to view the first 10 observations from this dataset:
/*view first 10 observations from Fish dataset*/ proc printdata=sashelp.Fish (obs=10); run;

Example 1: Correlation Between Two Variables
We can use the following code to calculate the Pearson correlation coefficient between the variables Height and Width:
/*calculate correlation coefficient between Height and Width*/ proc corrdata=sashelp.fish; var Height Width; run;

The first table displays summary statistics for both Height and Width.
The second table displays the Pearson correlation coefficient between the two variables, including a that tells us if the correlation is statistically significant.
From the output we can see:
- Pearson correlation coefficient: 0.79288
- P-value: <.0001
This tells us that there is a strong positive correlation between Height and Width and that the correlation is statistically significant since the p-value is less than α = .05.
Example 2: Correlation Between All Variables
We can use the following code to calculate the Pearson correlation coefficient between all pairwise combinations of variables in the dataset:
/*calculate correlation coefficient between all pairwise combinations of variables*/ proc corrdata=sashelp.fish; run;

The output shows a , which contains the Pearson correlation coefficient and corresponding p-values for each pairwise combination of numeric variables in the dataset.
For example:
- The Pearson correlation coefficient between Weight and Length1 is 0.91644
- The Pearson correlation coefficient between Weight and Length2 is 0.91937
- The Pearson correlation coefficient between Weight and Length3 is 0.92447
And so on.
Example 3: Visualize Correlation with a Scatterplot
We can also use the plots function to create a scatterplot to visualize the correlation between two variables:
/*visualize correlation between Height and Width*/ proc corrdata=sashelp.fish plots=scatter(nvar=all);; var Height Width; run;

From the plot we can see the strong positive correlation between Height and Width. As Height increases, Width tends to increase as well.
In the top left corner of the plot we can also see the total observations used, the correlation coefficient, and the p-value for the correlation coefficient.
Additional Resources
The following tutorials explain how to perform other common operations in SAS:
Cite this article
stats writer (2024). How can I calculate correlation in SAS? Can you provide some examples?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-calculate-correlation-in-sas-can-you-provide-some-examples/
stats writer. "How can I calculate correlation in SAS? Can you provide some examples?." PSYCHOLOGICAL SCALES, 1 Jul. 2024, https://scales.arabpsychology.com/stats/how-can-i-calculate-correlation-in-sas-can-you-provide-some-examples/.
stats writer. "How can I calculate correlation in SAS? Can you provide some examples?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-calculate-correlation-in-sas-can-you-provide-some-examples/.
stats writer (2024) 'How can I calculate correlation in SAS? Can you provide some examples?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-calculate-correlation-in-sas-can-you-provide-some-examples/.
[1] stats writer, "How can I calculate correlation in SAS? Can you provide some examples?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, July, 2024.
stats writer. How can I calculate correlation in SAS? Can you provide some examples?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
