*********************************************** * MACRO: EFFECTS * * THIS VERSION USES THE CALIBRATED LENTH TEST * * AS GIVEN IN LOUGHIN J. QUAL. TECHNOLOGY, * * 1998, 30, 2, 171-175. * ***********************************************; %window effect group=name #1 @4 'ENTER THE NAME OF YOUR DATA SET' @75 dname1 16 attr=underline color=green required=yes #2 @4 'ENTER THE NAME OF THE DATA FILE TO STORE THE OUTPUT' @75 oname1 11 attr=underline color=green required=yes #3 @4 'ENTER THE NAME OF THE RESPONSE VARIABLE' @75 resp1 11 attr=underline color=green required=yes #4 @4 'ENTER THE NUMBER OF MAIN EFFECTS IN THE MODEL' @75 k1 11 attr=underline color=green required=yes group=level #6 @4 'DO YOU WANT TO SPECIFY THE CONFIDENCE LEVEL?' #7 @4 ' (Y/N) (DEFAULT=.95)' @75 conf1 8 attr=underline color=green required=yes group=enterl #8 @4 'ENTER YOUR CONFIDENCE LEVEL' @75 conf2 8 attr=underline color=green required=yes group=num1 #10 @4 'ENTER THE NAME OF THE FIRST MAIN EFFECT' @75 ef1 8 attr=underline color=green required=yes group=num2 #11 @4 'ENTER THE NAME OF THE SECOND MAIN EFFECT' @75 ef2 8 attr=underline color=green required=yes group=num3 #12 @4 'ENTER THE NAME OF THE THIRD MAIN EFFECT' @75 ef3 8 attr=underline color=green required=yes group=num4 #13 @4 'ENTER THE NAME OF THE FOURTH MAIN EFFECT' @75 ef4 8 attr=underline color=green required=yes group=num5 #14 @4 'ENTER THE NAME OF THE FIFTH MAIN EFFECT' @75 ef5 8 attr=underline color=green required=yes group=num6 #15 @4 'ENTER THE NAME OF THE SIXTH MAIN EFFECT' @75 ef6 8 attr=underline color=green required=yes group=num7 #16 @4 'ENTER THE NAME OF THE SEVENTH MAIN EFFECT' @75 ef7 8 attr=underline color=green required=yes group=siglvl #18 @4 'CHOOSE A SIGNIFICANCE LEVEL FROM AMONG' #19 @4 '.01 (MOE ONLY), .05, .10, .20 (SMOE ONLY), OR .40 (SMOE ONLY)' @75 siglvl1 attr=underline color=green required=yes group=message #21 @4 'PLEASE USE' @15 'SAS/INSIGHT' color=green @27 'TO MAKE THE NORMAL QUANTILE PLOT;' #22 @4 ' THE DATA IS PLACED IN' @36 'WORK.DRANK' color=green @46 ';' #23 @4 ' PLEASE USE' @20 'QUANTILE' color=green @29 'AS A VERTICAL AXIS VARIABLE,' #24 @4 ' USE' @15 'ESTIMATE' color=green @24 'AS A HORIZONTAL AXIS VARIABLE' #25 @4 ' AND USE' @18 'LABEL' color=green @24 'AS A LABEL VARIABLE. GOOD LUCK!' #27 @4 'HIT RETURN TO EXIT THIS MACRO' color=green attr=rev_video group=error #29 @10 'YOU HAVE ENTERED AN INVALID VALUE.' #30 @10 'THE MAXIMUM NUMBER OF MAIN EFFECTS IS 7.' #31 @10 'THE MINIMUM NUMBER OF MAIN EFFECTS IS 3.' #32 @10 'PLEASE HIT RETURN, THEN TRY AGAIN.'; %macro c_lenth; * THE NAMES OF DATA SET & OUTPUT FILE AND RESPONSE VARIABLE & NUMBER OF MAIN FACTORS ARE PROVIDED BY USERS; %choice: %display effect.name; %let dname=&dname1; %let dname1=; %let oname=&oname1; %let oname1=; %let resp=&resp1; %let resp1=; %let k=&k1; %let k1=; %if &k > 7 %then %goto err; %if &k < 3 %then %goto err; *LOOP FOR ENTERING NAMES OF MAIN FACTORS; %do i=1 %to &k; %display effect.num&i; %let eff&i=&&ef&i; %let ef&i=; %end; %display effect.siglvl; %let siglvl=&siglvl1; %let siglvl1=; * GENERATE ALL INTERACTION VARIABLES; %macro startn; &resp %do i=1 %to &k; &&eff&i %end; %mend startn; data start; set &dname; keep %startn; run; data out1; set start; label &resp="&resp"; %do i=1 %to &k; label &&eff&i="&&eff&i"; %end; %do i1=1 %to &k-1; %if &k>=2 %then %do; %do i2=&i1+1 %to &k; I&i1&i2=&&eff&i1*&&eff&i2; label I&i1&i2="&&eff&i1*&&eff&i2"; %if (&k>=3) and (&i1<&k-1) and (&i2<&k) %then %do; %do i3=&i2+1 %to &k; I&i1&i2&i3=&&eff&i1*&&eff&i2*&&eff&i3; label I&i1&i2&i3="&&eff&i1*&&eff&i2*&&eff&i3"; %if (&k>=4) and (&i1<&k-2) and (&i2<&k-1) and (&i3<&k) %then %do; %do i4=&i3+1 %to &k; I&i1&i2&i3&i4=&&eff&i1*&&eff&i2*&&eff&i3*&&eff&i4; label I&i1&i2&i3&i4="&&eff&i1*&&eff&i2*&&eff&i3*&&eff&i4"; %if (&k>=5) and (&i1<&k-3) and (&i2<&k-2) and (&i3<&k-1) and (&i4<&k) %then %do; %do i5=&i4+1 %to &k; I&i1&i2&i3&i4&i5=&&eff&i1*&&eff&i2*&&eff&i3*&&eff&i4 *&&eff&i5; label I&i1&i2&i3&i4&i5= "&&eff&i1*&&eff&i2*&&eff&i3*&&eff&i4*&&eff&i5"; %if (&k>=6) and (&i1<&k-4) and (&i2<&k-3) and (&i3<&k-2) and (&i4<&k-1) and (&i5<&k) %then %do; %do i6=&i5+1 %to &k; I&i1&i2&i3&i4&i5&i6=&&eff&i1*&&eff&i2*&&eff&i3*&&eff&i4 *&&eff&i5*&&eff&i6; label I&i1&i2&i3&i4&i5&i6= "&&eff&i1*&&eff&i2*&&eff&i3*&&eff&i4*&&eff&i5*&&eff&i6"; %if (&k>=7) and (&i1<&k-5) and (&i2<&k-4) and (&i3<&k-3) and (&i4<&k-2) and (&i5<&k-1) and (&i6<&k) %then %do; I1234567=&eff1*&eff2*&eff3*&eff4*&eff5*&eff6*&eff7; label I1234567="&eff1*&eff2*&eff3*&eff4*&eff5*&eff6*&eff7"; %end; %end; %end; %end; %end; %end; %end; %end; %end; %end; %end; %end; run; * CREATE VARIABLE NAME MACRO; %macro names(namea,nameb); %do i=1 %to &k; &&&namea&i %end; %do i1=1 %to &k-1; %if &k>=2 %then %do; %do i2=&i1+1 %to &k; &nameb&i1&i2 %if (&k>=3) and (&i1<&k-1) and (&i2<&k) %then %do; %do i3=&i2+1 %to &k; &nameb&i1&i2&i3 %if (&k>=4) and (&i1<&k-2) and (&i2<&k-1) and (&i3<&k) %then %do; %do i4=&i3+1 %to &k; &nameb&i1&i2&i3&i4 %if (&k>=5) and (&i1<&k-3) and (&i2<&k-2) and (&i3<&k-1) and (&i4<&k) %then %do; %do i5=&i4+1 %to &k; &nameb&i1&i2&i3&i4&i5 %if (&k>=6) and (&i1<&k-4) and (&i2<&k-3) and (&i3<&k-2) and (&i4<&k-1) and (&i5<&k) %then %do; %do i6=&i5+1 %to &k; &nameb&i1&i2&i3&i4&i5&i6 %if (&k>=7) and (&i1<&k-5) and (&i2<&k-4) and (&i3<&k-3) and (&i4<&k-2) and (&i5<&k-1) and (&i6<&k) %then %do; &nameb.1234567 %end; %end; %end; %end; %end; %end; %end; %end; %end; %end; %end; %end; %mend names; * OUTPUTS ALL INTERACTION VARIABLES ALONG WITH THE RESPONSES AND FACTORS; data &oname; set out1; run; data contin; set out1; drop &resp; run; proc contents data=contin out=cont noprint; run; proc sort data=cont out=cont; by name; run; data cont; set cont; keep label; goptionsy reset=(symbol title axis) /* device=xcolor gaccess=sasgaedt gsfname=gsasfile gprolog='25210D0A'x gsfmode=replace gsflen=80 */ ; title "RESPONSE: &resp"; proc print data=&oname label noobs; var %names(eff,I); format %names(eff,I); run; title; * COMPUTE ESTIMATES FOR ALL MAIN FACTORS AND INTERACTIONS; proc reg data=out1 outest=out2 noprint; estimate: model &resp=%names(eff,I); run; proc transpose data=out2 out=out3 name=effect; var %names(eff,I); run; data out3; set out3; estimate=2*col1; keep effect estimate; * CREATE THE DATA WORK.DRANK FOR NORMAL QUANTILE PLOT; goptions reset=(symbol title axis) /* device=xcolor gaccess=sasgaedt gsfname=gsasfile gprolog='25210D0A'x gsfmode=replace gsflen=80 */ ; proc rank data=out3 out=drank ties=mean normal=blom; var estimate; ranks blomrank; data drank; set drank; quantile=blomrank; keep effect quantile estimate; run; proc sort data=drank out=drank; by effect; run; data drank; merge drank cont; run; * COMPUTE MOE AND SMOE USING LENTH PROCEDURE; data out4; set out3; astimate=abs(estimate); magic=1; run; proc univariate data=out4 noprint; var astimate; output out=lenth1 median=medac; by magic; run; data out5; merge out4 lenth1; by magic; run; data out6; set out5; s0=1.5*medac; cstar=astimate; if cstar ge 2.5*s0 then cstar=.; run; proc univariate data=out6 noprint; var cstar; output out=lenth2 median=medacst; by magic; run; data out7; merge out6 lenth2; by magic; %if &siglvl=.01 %then %goto lvl01; %if &siglvl=.05 %then %goto lvl0510; %if &siglvl=.10 %then %goto lvl0510; %if &siglvl=.20 %then %goto lvl2040; %if &siglvl=.40 %then %goto lvl2040; %goto err; %lvl0510: data out7; set out7; pse=1.5*medacst; m=2**(&k)-1; if &k=3 and &siglvl=.05 then do; moe=pse*2.3; smoe=pse*4.878; end; if &k=3 and &siglvl=.10 then do; moe=pse*1.710; smoe=pse*3.677; end; if &k=4 and &siglvl=.05 then do; moe=pse*2.152; smoe=pse*4.242; end; if &k=4 and &siglvl=.10 then do; moe=pse*1.703; smoe=pse*3.502; end; if &k=5 and &siglvl=.05 then do; moe=pse*2.066; smoe=pse*3.910; end; if &k=5 and &siglvl=.10 then do; moe=pse*1.679; smoe=pse*3.453; end; if &k=6 and &siglvl=.05 then do; moe=pse*2.013; smoe=pse*3.813; end; if &k=6 and &siglvl=.10 then do; moe=pse*1.666; smoe=pse*3.472; end; if &k=7 and &siglvl=.05 then do; moe=pse*1.989; smoe=pse*3.809; end; if &k=7 and &siglvl=.10 then do; moe=pse*1.657; smoe=pse*3.545; end; * moe=pse*tinv((1+&gamma)/2,m/3); * smoe=pse*tinv((1+&gamma**(1/m))/2,m/3); mmoe=-moe; msmoe=-smoe; keep effect estimate moe mmoe smoe msmoe; run; * OUTPUTS ESTIMATES, MOE AND MSE; proc sort data=out7 out=out7; by effect; run; data out7; merge out7 cont; title "RESPONSE: &resp"; proc print data=out7 noobs; *var effect label estimate moe mmoe smoe msmoe; *format effect label estimate moe mmoe smoe msmoe; var effect label estimate moe smoe; format effect label estimate moe smoe; run; title; * DISPLAY THE PLOT SHOWING THE EFFECTS AND THE VALUES OF MOE AND MSE; symbol1 color=red i=needle; symbol2 color=blue i=j line=2; symbol3 color=blue i=j line=2; symbol4 color=brown i=j line=3; symbol5 color=brown i=j line=3; %if &k=7 %then %goto next; axis1 label=('EFFECT'); proc gplot data=out7; title1 color=green height=4 pct "THE MOE AND SMOE PLOT (LEVEL = &siglvl)"; title2 color=green "RESPONSE: &resp"; plot (estimate moe mmoe smoe msmoe)*effect/frame overlay haxis=axis1; run; quit; %goto finish; %next: data out71; set out7; id=_n_; if id <= 64; data out72; set out7; id=_n_; if id > 64; axis1 label=('EFFECT'); proc gplot data=out71; title1 color=green height=4 pct "THE FIRST HALF OF MOE AND SMOE PLOT (LEVEL = &siglvl)"; title2 color=green "RESPONSE: &resp"; plot (estimate moe mmoe smoe msmoe)*effect/frame overlay haxis=axis1; run; quit; axis1 label=('EFFECT'); proc gplot data=out72; title1 color=green height=4 pct "THE SECOND HALF OF MOE AND SMOE PLOT (LEVEL = &siglvl)"; title2 color=green "RESPONSE: &resp"; plot (estimate moe mmoe smoe msmoe)*effect/frame overlay haxis=axis1; run; quit; %goto finish; %lvl01: data out7; set out7; pse=1.5*medacst; m=2**(&k)-1; if &k=3 then moe=pse*5.085; if &k=4 then moe=pse*3.618; if &k=5 then moe=pse*3.043; if &k=6 then moe=pse*2.798; if &k=7 then moe=pse*2.687; mmoe=-moe; keep effect estimate moe mmoe; run; * OUTPUTS ESTIMATES, MOE AND MSE; proc sort data=out7 out=out7; by effect; run; data out7; merge out7 cont; title "RESPONSE: &resp"; proc print data=out7 noobs; *var effect label estimate moe mmoe smoe msmoe; *format effect label estimate moe mmoe smoe msmoe; var effect label estimate moe; format effect label estimate moe; run; title; * DISPLAY THE PLOT SHOWING THE EFFECTS AND THE VALUES OF MOE AND MSE; symbol1 color=red i=needle; symbol2 color=blue i=j line=2; symbol3 color=blue i=j line=2; %if &k=7 %then %goto next1; axis1 label=('EFFECT'); proc gplot data=out7; title1 color=green height=4 pct "THE MOE PLOT (LEVEL = &siglvl)"; title2 color=green "RESPONSE: &resp"; plot (estimate moe mmoe )*effect/frame overlay haxis=axis1; run; quit; %goto finish; %next1: data out71; set out7; id=_n_; if id <= 64; data out72; set out7; id=_n_; if id > 64; axis1 label=('EFFECT'); proc gplot data=out71; title1 color=green height=4 pct "THE FIRST HALF OF MOE PLOT (LEVEL = &siglvl)"; title2 color=green "RESPONSE: &resp"; plot (estimate moe mmoe)*effect/frame overlay haxis=axis1; run; quit; axis1 label=('EFFECT'); proc gplot data=out72; title1 color=green height=4 pct "THE SECOND HALF OF MOE PLOT (LEVEL = &siglvl)"; title2 color=green "RESPONSE: &resp"; plot (estimate moe mmoe)*effect/frame overlay haxis=axis1; run; quit; %goto finish; %lvl2040: data out7; set out7; pse=1.5*medacst; m=2**(&k)-1; if &k=3 and &siglvl=.20 then smoe=pse*2.427; if &k=3 and &siglvl=.40 then smoe=pse*1.804; if &k=4 and &siglvl=.20 then smoe=pse*2.837; if &k=4 and &siglvl=.40 then smoe=pse*2.143; if &k=5 and &siglvl=.20 then smoe=pse*2.977; if &k=5 and &siglvl=.40 then smoe=pse*2.422; if &k=6 and &siglvl=.20 then smoe=pse*3.117; if &k=6 and &siglvl=.40 then smoe=pse*2.716; if &k=7 and &siglvl=.20 then smoe=pse*3.262; if &k=7 and &siglvl=.40 then smoe=pse*2.929; msmoe=-smoe; keep effect estimate smoe msmoe; run; * OUTPUTS ESTIMATES, SMOE AND MSE; proc sort data=out7 out=out7; by effect; run; data out7; merge out7 cont; title "RESPONSE: &resp"; proc print data=out7 noobs; *var effect label estimate moe mmoe smoe msmoe; *format effect label estimate moe mmoe smoe msmoe; var effect label estimate smoe; format effect label estimate smoe; run; title; * DISPLAY THE PLOT SHOWING THE EFFECTS AND THE VALUES OF SMOE AND MSE; symbol1 color=red i=needle; symbol2 color=brown i=j line=3; symbol3 color=brown i=j line=3; %if &k=7 %then %goto next2; axis1 label=('EFFECT'); proc gplot data=out7; title1 color=green height=4 pct "THE SMOE PLOT (LEVEL = &siglvl)"; title2 color=green "RESPONSE: &resp"; plot (estimate smoe msmoe )*effect/frame overlay haxis=axis1; run; quit; %goto finish; %next2: data out71; set out7; id=_n_; if id <= 64; data out72; set out7; id=_n_; if id > 64; axis1 label=('EFFECT'); proc gplot data=out71; title1 color=green height=4 pct "THE FIRST HALF OF SMOE PLOT (LEVEL = &siglvl)"; title2 color=green "RESPONSE: &resp"; plot (estimate smoe msmoe)*effect/frame overlay haxis=axis1; run; quit; axis1 label=('EFFECT'); proc gplot data=out72; title1 color=green height=4 pct "THE SECOND HALF OF SMOE PLOT (LEVEL = &siglvl)"; title2 color=green "RESPONSE: &resp"; plot (estimate smoe msmoe)*effect/frame overlay haxis=axis1; run; quit; %goto finish; %err: %display effect.error; %goto choice; %finish: goptions reset=(symbol axis title); title; %display effect.message; %mend c_lenth; *%c_lenth;