Hi, I'm trying to output a full matrix of tetrachoric correlations, like the matrix produced by proc corr outp= option.
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:
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!
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;
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;
/*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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.