BookmarkSubscribeRSS Feed
jhs2171
Obsidian | Level 7

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!

7 REPLIES 7
Reeza
Super User

Proc CORR - check default plots first?

jhs2171
Obsidian | Level 7
Hello.Thank you for your reply! My question is how do I specify the tetrachoric option in the PROC CORR (i.e. GPLOT)? I've used the tetrachoric in PROC FREQ in lieu of PROC CORR so I wasn't sure how to generate a plot/graph in this case. Hope this makes sense!!
Rick_SAS
SAS Super FREQ

 

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;

j.png

jhs2171
Obsidian | Level 7
Hi Rick,
Thank you for your reply- Quick question in the Step 1 process:
proc corr data=ordinal polychoric outplc=OUT;
var x1-x5;
run;

I am not sure what 'outplc" does, did you mean outp? Also having 'polychoric' in PROC CORR gave me an error message- any suggestion?

Thank you!
jhs2171
Obsidian | Level 7

Thanks for the link! I guess the polychoric option didn't work because I am using SAS 9.3? Not sure. Anyway, thank you! 

Rick_SAS
SAS Super FREQ

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is ANOVA?

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.

Discussion stats
  • 7 replies
  • 2058 views
  • 0 likes
  • 3 in conversation