*indicating the directory of the sim.sas7bdat data file, change as needed; libname example 'c:\example\'; *printing data for the first two Level 2 units (corresponding to top of Table 1); proc print data=example.sim; where id le 2; var id Y M X; run; *rearranging the data to permit fitting the lower level mediation model; data rearrange; set example.sim; Z = Y; *first assigning Z the value of Y; Sy = 1; *setting Sy selection variable to 1 to indicate Z is Y; Sm = 0; *setting Sm selection variable to 0 to indicate Z is not M; dv = 'Y'; *creating variable dv also to differentiate Y from M; output; *outputting the first record for the observation; Z = M; *now assigning Z the value of M; Sy = 0; *setting Sy selection variable to 0 to indicate Z is not Y; Sm = 1; *setting Sm selection variable to 1 to indicate Z is M; dv = 'M'; *creating variable dv also to differentiate Y from M; output; *outputting the second record for the observation; run; *printing the rearranged data for the first two Level 2 units (corresponding to the bottom of Table 1); proc print data=rearrange; where id le 2; var id Z Sy Sm M X dv; run; *fitting the lower level mediation model; proc mixed data=rearrange asycov covtest noclprint method=reml maxiter=100; class dv; model Z = Sm Sm*X Sy Sy*M Sy*X /noint solution ddfm=kr covb; random Sm Sm*X Sy Sy*M Sy*X/g gcorr type=un subject=id; repeated / group=dv subject=id; run; ******** using indtest macro ********; *telling SAS where the IndTest.sas file is stored and to include it here; %include 'c:\macros\IndTest.sas'; *adding ODS statement to MIXED syntax; proc mixed data=rearrange asycov covtest noclprint method=reml maxiter=100; class dv; model Z = Sm Sm*X Sy Sy*M Sy*X /noint solution ddfm=kr covb; random Sm Sm*X Sy Sy*M Sy*X/g gcorr type=un subject=id; repeated / group=dv subject=id; ods output covb=acovfix asycov=acovrand solutionf=estfix covparms=estrand convergencestatus=converge; run; *calling macro; %Indtest(p1=2,p2=4,p3=5,p4=8,draws=10000,seed=123,alpha=.05);