BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
awesome_opossum
Obsidian | Level 7

Hi, I'm trying to output a full matrix of tetrachoric correlations, like the matrix produced by proc corr outp= option. 

awesome_opossum_0-1663696887080.png

Proc corr does have an option for outputting tetrachoric correlations: 

 

proc corr data = data polychoric;
var var1 var2 var3 var4;
ods output PolychoricCorr = tcorr;
run;

 

However, it outputs the data like so: 

awesome_opossum_1-1663696962598.png

 

I've heard there are macros out there that can do this, but I'm wondering if there's maybe a simpler solution or other procedure/option that could do this without having to bother with a macro? 

 

Alternatively (as I also posted in Programming community), I am open to method that could shift the column values into the matrix, if there is one that isn't too dangerously complicated.

 

Also alternatively, I might be open to getting a full matrix of Yule's Y instead of the tetrachoric correlations, if anyone knows how to do that and it is easier. 

 

Thanks! 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Not aware of an option/procedure. You basically need to do the data manipulation.

 


data tcorr2;
	set tcorr;
	by var;
	output;
	t_var=withVar;
	withVar=var;
	var=t_var;
	output;
	drop t_var;
run;

proc sort data=tcorr2;
	by var withVar;
run;

data tcorr3;
	set tcorr2;
	by var;
	output;

	if first.var then
		do;
			withVar=var;
			corr=1;
			output;
		end;
run;

proc sort data=tcorr3;
	by var withVar;
run;

proc transpose data=tcorr3 out=want;
	by var;
	id withVar;
	var corr;
run;

View solution in original post

4 REPLIES 4
Reeza
Super User

Not aware of an option/procedure. You basically need to do the data manipulation.

 


data tcorr2;
	set tcorr;
	by var;
	output;
	t_var=withVar;
	withVar=var;
	var=t_var;
	output;
	drop t_var;
run;

proc sort data=tcorr2;
	by var withVar;
run;

data tcorr3;
	set tcorr2;
	by var;
	output;

	if first.var then
		do;
			withVar=var;
			corr=1;
			output;
		end;
run;

proc sort data=tcorr3;
	by var withVar;
run;

proc transpose data=tcorr3 out=want;
	by var;
	id withVar;
	var corr;
run;
awesome_opossum
Obsidian | Level 7
Always the best, Reeza. Thank you!
StatDave
SAS Super FREQ
When you are looking for a particular statistic in SAS, check the list of Frequently Asked-for Statistics (FASTats) in the Important Links section of the Statistical Procedures Community page. As noted there in the "Tetrachoric correlation matrix" and "Correlations" items, you can use the OUTPLC= option in PROC CORR.
Ksharp
Super User
/*It is a SAS/IML thing*/
data have;
   input var $ withvar $ corr;
datalines;
var1 var2  0.096
var1 var3  -0.062
var1 var4  0.097
var2 var3  -0.413
var2 var4  -0.0037
var3 var4  0.074
;

proc iml;
use have;
read all var{var withvar corr};
close;
x=corr||num(compress(var,,'kd'))||num(compress(withvar,,'kd'));
f=full(x);
n=ncol(f);
w=f//j(1,n,0);
want=w+t(w)+i(n);
vname='var1':'var'+char(n);
create want from want[c=vname r=vname ];
append from want[r=vname];
close;
quit;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 4 replies
  • 917 views
  • 6 likes
  • 4 in conversation