Hi
I want to create a scatter plot (or any graphs that are visiually appealing!) of the correlation matrix between two dichotomous variables in my dataset. I used the plrr option in PROC FREQ to get the basic statistics including tetrachoric correlation and OR. I've never created any graphs in SAS so any help would be greatly appreciated!
Thank you!
Proc CORR - check default plots first?
Geting PROC CORR to generate polychoric correlations in a data set and then plotting them is no different than for ordinary Pearson correlations. See @ChrisHemedinger's blog post for a discussion in SAS 9.3.
Since you didn't provide data, here is some sample data to play with. The data is from the SAS Sample on how to create a polychoric matrix.
data norm;
length id $ 8;
array x{5} x1-x5;
do n=1 to 20;
do i=1 to 5;
x{i}=rannor(238423)*3+10;
end;
id=cats(n,'');
keep id x1-x5;
output;
end;
run;
proc rank data=norm out=ordinal groups=5;
var x1-x5;
run;
There are three main steps to the analysis. The graph is created by using the HEATMAP statement in PROC SGPLOT, which was introduced in SAS 9.4m3.:
/* 1. Create OUT data set that contains correlations in matrix form */
proc corr data=ordinal polychoric outplc=OUT;
var x1-x5;
run;
/* 2. transpose from wide to long */
proc transpose data=Out(where=(_TYPE_="CORR"))
name=ID out=Have(rename=(COL1=Value) drop=_LABEL_);
var x1-x5;
by _NAME_;
run;
/* 3. Plot with scatter plot or heat map */
title "Polychoric Correlations";
proc sgplot data=Have;
heatmap x=_NAME_ y=ID / colorresponse=Value discretex discretey;
yaxis reverse display=(nolabel);
xaxis display=(nolabel);
run;
Here is a link to the documentation for the PROC CORR statement:
Thanks for the link! I guess the polychoric option didn't work because I am using SAS 9.3? Not sure. Anyway, thank you!
The documentation says
"In the Second Maintenance Release of SAS 9.3, the POLYCHORIC option has been added to the PROC CORR statement."
Therefore you need 9.3m2to use the opiton. SAS 9.3m2 was released in Aug 2012. I strongly encourage you to upgrade to SAS 9.4. You are also missing a HUGE number of new features, especially related to ODS graphics and the SGPLOT procedure. I mentioned the HEATMAP statement, but that is just one instance.
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 25. Read more here about why you should contribute and what is in it for you!
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.