Thursday, March 27, 2008

Coding interactions/effect modification to get Confidence Intervals

/************ THIS IS 4 X 3 interaction *************/


VARA0VARB0=0; VARA0VARB1=0;VARA0VARB2=0; VARA0VARB3=0;
VARA1VARB0=0; VARA1VARB1=0;VARA1VARB2=0; VARA1VARB3=0;
VARA2VARB0=0; VARA2VARB1=0;VARA2VARB2=0; VARA2VARB3=0;
VARA3VARB0=0; VARA3VARB1=0;VARA3VARB2=0; VARA3VARB3=0;

IF VARA=0 THEN DO;
IF VARB=0 THEN VARA0VARB0=0;
IF VARB=1 THEN VARA0VARB1=1;
IF VARB=2 THEN VARA0VARB2=2;
IF VARB=3 THEN VARA0VARB3=3;
END;

IF VARA=1 THEN DO;
IF VARB=0 THEN VARA1VARB0=0;
IF VARB=1 THEN VARA1VARB1=1;
IF VARB=2 THEN VARA1VARB2=2;
IF VARB=3 THEN VARA1VARB3=3;
END;

IF VARA=2 THEN DO;
IF VARB=0 THEN VARA2VARB0=0;
IF VARB=1 THEN VARA2VARB1=1;
IF VARB=2 THEN VARA2VARB2=2;
IF VARB=3 THEN VARA2VARB3=3;
END;

IF VARA=3 THEN DO;
IF VARB=0 THEN VARA3VARB0=0;
IF VARB=1 THEN VARA3VARB1=1;
IF VARB=2 THEN VARA3VARB2=2;
IF VARB=3 THEN VARA3VARB3=3;
END;

%LET VARB_VARAINT=
VARA0VARB1 VARA0VARB2 VARA0VARB3
VARA1VARB0 VARA1VARB1 VARA1VARB2 VARA1VARB3
VARA2VARB0 VARA2VARB1 VARA2VARB2 VARA2VARB3
VARA3VARB0 VARA3VARB1 VARA3VARB2 VARA3VARB3;

/* To find the point estimates and confidence intervals of each level of VARA with each level of VARB just enter the &VARB_VARAINT
in the models */

/* you can tailor the code with find and replace in SAS/Xemacs/Word/Textpad. */


/************ THIS IS 4 X 4 interaction *************/


VARA0VARB0=0; VARA0VARB1=0; VARA0VARB2=0; VARA0VARB3=0; /* 1ST QUINTILE*/
VARA1VARB0=0; VARA1VARB1=0; VARA1VARB2=0; VARA1VARB3=0; /* 2ND QUINTILE*/
VARA2VARB0=0; VARA2VARB1=0; VARA2VARB2=0; VARA2VARB3=0; /* 3RD QUINTILE */
VARA3VARB0=0; VARA3VARB1=0; VARA3VARB2=0; VARA3VARB3=0; /* 4TH QUINTILE */

IF VARA=0 then do;
if VARB=0 then VARA0VARB0=1;
if VARB=1 then VARA0VARB1=1;
if VARB=2 then VARA0VARB2=1;
if VARB=3 then VARA0VARB3=1;
END;

IF VARA=1 then do;
if VARB=0 then VARA1VARB0=1;
if VARB=1 then VARA1VARB1=1;
if VARB=2 then VARA1VARB2=1;
if VARB=3 then VARA1VARB3=1;
END;

IF VARA=2 then do;
if VARB=0 then VARA2VARB0=1;
if VARB=1 then VARA2VARB1=1;
if VARB=2 then VARA2VARB2=1;
if VARB=3 then VARA2VARB3=1;
END;


IF VARA=3 then do;
if VARB=0 then VARA3VARB0=1;
if VARB=1 then VARA3VARB1=1;
if VARB=2 then VARA3VARB2=1;
if VARB=3 then VARA3VARB3=1;
END;


%LET VARA_VARBINT=
VARA0VARB1 VARA0VARB2 VARA0VARB3
VARA1VARB0 VARA1VARB1 VARA1VARB2 VARA1VARB3
VARA2VARB0 VARA2VARB1 VARA2VARB2 VARA2VARB3
VARA3VARB0 VARA3VARB1 VARA3VARB2 VARA3VARB3 ;