%MACRO SRMText (outcome=outcome,oname='Outcome',dir="C:\",file=data,actor=actor,partner=partner,group=group,ofile='c:\srmtext.txt');
data g;
do i = 1 to 25;parm=1;row=i;col=i;value=1;output;end;
do i = 1 to 25;parm=2;row=i+25;col=i+25;value=1;output;end;
do i = 1 to 25;parm=3;row=i;col=i+25;value=1;output;end;
drop i;
data ddd ;
libname dir &dir;set dir.&file;
array a(25)a1-a25;array p(25) p1-p25;do i = 1 to 25;if i = &actor then a(i)= 1;else a(i)=0;
if i = &partner then p(i)=1;else p(i)=0;end;
dd=0;do i = 1 to 24;do j = i+1 to 25;dd=dd+1;if &actor=i and &partner=j then dyad=dd;if &actor=i and &partner=j then member=1;
if &actor=j and &partner=i then dyad=dd;if &actor=j and &partner=i then member=2;end;end;
ods trace on;
proc mixed covtest ;class DYAD &group member;
model &Outcome =   /s ddfm =SATTERTH ;
random intercept/ sub=&group type=vc ;
random   a1-a25 p1-p25 / gcorr sub=&group type =lin(3) ldata = g ;
repeated member / rcorr sub=dyad(&group) type=cs;
ods output solutionf= sf;ods output covparms= vc;
run;
DATA MXX;SET VC;
proc transpose out=vc2;
data mox;
set vc2;
IF _N_ = 1 THEN totvar = col1 + col2+col3+col6;
IF _N_ = 1 and col1 < 0 THEN totvar = col2+col3+col6;
IF _N_ = 1 and col2 < 0 THEN totvar = col1+col3+col6;
IF _N_ = 1 and col3 < 0 THEN totvar = col2+col1+col6;
IF _N_ = 1 THEN pvar = col3*col2;
IF _N_ = 1 THEN dvar = col6;
proc univariate noprint;
var totvar pvar dvar ;
output out=mmm mean=mean pvar dvar;run;quit;
run;
data mom; set mmm;run;
data vxc; 
if _n_ = 1 then set mom  ; 
set vc sf ;
attrib hh gg dd format=$196.;
attrib probz format=f4.3;
attrib estimate estr format=f14.3;
sv=0.0000001;
if _N_ = 1 then gg = "relative group variance";
if _N_ = 2 then gg = "relative actor variance";
if _N_ = 3 then gg = "relative partner variance";
if _N_ = 4 then gg = "actor-partner correlation";
if _N_ = 5 then gg = "dyadic correlation";
if _N_ = 6 then gg = "relative error variance";
if _N_ = 7 then gg = Cat("grand mean for the ",trim(&oname));
if _N_ = 1 or _N_ = 2 or _N_ =3 or _N_ = 6 then estr=estimate/mean;
if _N_ = 1 and estr < 0.0 then estr=0;
if _N_ = 2 and estr < 0.0 then estr=0;
if _N_ = 3 and estr < 0.0 then estr=0;
if _N_ = 5 then estr=estimate/DVAR;
if _N_ = 4 and pvar > .00 then estr=estimate/SQRT(PVAR);
if _N_ = 7 then estr=estimate;
yy=0;
if _N_ = 4 and lag1(estimate) < sv then yy=1;
if _N_ = 4 and lag2(estimate) < sv then yy=1;
cac = 'The ';
gga = ' is equal to';
dd=Left(Round(estr,.001));
sig = ", which is";
if estimate < sv then goto xyx;
if _N_ = 1 or _N_ = 2 or _N_ = 3 or _N_ = 6 and estimate > 0 then probz=probz/2 ;
goto hxhx;
xyx: if _N_ = 1 or _N_ = 2 or _N_ = 3 or _N_ = 6 and estimate < 0. then probz=1-probz/2;
hxhx:pv=left(Round(probZ,.001));
if pv = "0" then pv="< .001"; else pv = Cat("= ",pv); 
dirr=                      "           statistically significant";
if probz > .05 then dirr=  "marginally statistically significant";
if probz >= .10 then dirr= "       not statistically significant";
sigs=Cat(sig," ",strip(dirr)," (p ", strip(pv),").");
if _N_ = 7 or _N_ = 6 then sigs='.';
hh= Cat(cac,trim(gg),gga," ",trim(dd), sigs);
if yy=1 and _N_=4 then hh="Because either the actor or the partner variance is not positive, the actor-partner correlation cannot be computed.";
keep hh;
run; quit;
DATA FIF;
SET vxc;
filename test &ofile LRECL=1056;
attrib  x1 x2 x3 x4 x5 x6 x7 format=$196.;
attrib  xxx format=$1896.;
X1 = Strip(HH);
X2 = strip(LAG6(HH));
X3 = strip(LAG5(HH));
X4 = strip(LAG4(HH));
X5 = strip(LAG1(HH));
X6 = strip(LAG3(HH));
X7 = strip(LAG2(HH));
xxx=Cat(strip(x1)," ",strip(x2)," ",strip(x3)," ",strip(x4)," ",strip(x5)," ",strip(x6)," ",strip(x7));
if _N_ < 7 then delete;
file test;
blank="          ";
put blank xxx;
keep xxx;
RUN; QUIT;
%MEND SRMText; 

