Transcript Document

Tips & Tricks
From your fellow SAS users
9/30/2004
Mehmet Kocak
St. Jude
Topic:
Shapiro-Wilk Normality Test
Shapiro-Wilk Normality Test
Once you call the macro, here are the parameters you specify:
%histogram(data, var, barnum, byvar=none, group=none,
numeric=no, title=);
DATA: Data set where you have the variable to check normality;
VAR: Variable for which to check normality;
BARNUM:Number of bars to be shown in the histogram;
BYVAR: specifies if you want to check normality for some
subgroups;
GROUP: specifies group for which to check normality;
NUMERIC: specifies if the grouping variable is numberic or
categorical (numeric=no/yes) ;
TITLE: If no title is specified, then the title is "The Histogram of
Variable &VAR"; using this TITLE statement, you can add to the
default title;
An example can be %histogram(IQData, IQ, 12,
byvar=GENDER, group=MALE, numeric=no, title=
For Male Patients);
%macro histogram(data, var, barnum, byvar=none, group=none, numeric=no, title=);
%if &byvar=none %then %do;
proc sql noprint; title ""; select distinct min(&var), max(&var), (max(&var)-min(&var))/&barnum
into :minval, :maxval, :wdt from &data; quit;
proc univariate data=&data normal noprint;
title "Univariate Analysis for &var";
var &var; output out=Normal&data normal=normtest probn=pvalue noprint; run;
data _null_; set normal&data; if pvalue<0.001 then do; x="<0.001";
call symput("Pvalue", x); end;
else call symput ("pvalue", pvalue); run;
%let pvalue=%substr(&pvalue, 1,6);
proc univariate data=&data normal noprint;
title "";
var &var;
title "Univariate Analysis for &var";
title1 height=5 font="complex" bold "Histogram of Variable %upcase(&var) &title";
title2 height=5 font=simplex "P-value for Shapiro-Wilk Normality Test=&pvalue";
histogram &var/normal(noprint) height=5 font=complex midpoints=&minval to &maxval by &wdt;
run;
%end;
%else %if &byvar^=none and &numeric=no %then %do;
proc sql noprint; title ""; select distinct min(&var), max(&var), (max(&var)-min(&var))/&barnum
into :minval, :maxval, :wdt from &data where &byvar="&group"; quit;
proc univariate data=&data normal noprint; where &byvar="&group";
title height=0.1 "Univariate Analysis for &var in Group %upcase(&group)";
var &var; output out=Normal&data normal=normtest probn=pvalue; run;
data _null_; set normal&data; if pvalue<0.001 then do; x="<0.001";
call symput("Pvalue", x); end;
else call symput ("Pvalue", pvalue); run;
%let pvalue=%substr(&pvalue, 1,6);
proc univariate data=&data noprint; where &byvar="&group";
title "";
var &var;
title "Univariate Analysis for &var in Group %upcase(&group)";
title1 height=5 font="complex" bold
"Histogram of Variable %upcase(&var) for %upcase(&group) &title";
title2 height=5 font=simplex "P-value for Shapiro-Wilk Normality Test=&pvalue";
histogram &var/normal(noprint) height=5 font=complex midpoints=&minval to &maxval by &wdt;
run;
%end;
%else %if &byvar^=none and &numeric^=no %then %do;
proc sql noprint; title ""; select distinct min(&var), max(&var), (max(&var)-min(&var))/&barnum
into :minval, :maxval, :wdt from &data where &byvar=&group; quit;
proc univariate data=&data normal noprint; where &byvar=&group;
title height=0.1 "Univariate Analysis for &var in Group %upcase(&group)";
var &var; output out=Normal&data normal=normtest probn=pvalue; run;
data _null_; set normal&data; if pvalue<0.001 then do; x="<0.001";
call symput("Pvalue", x); end;
else call symput ("Pvalue", pvalue); run;
%let pvalue=%substr(&pvalue, 1,6);
proc univariate data=&data noprint; where &byvar=&group;
title "";
var &var;
title "Univariate Analysis for &var in Group &group";
title1 height=5 font="complex" bold
"Histogram of Variable %upcase(&var) for &group &title";
title2 height=5 font=simplex "P-value for Shapiro-Wilk Normality Test=&pvalue";
histogram &var/normal(noprint) height=5 font=complex midpoints=&minval to &maxval by &wdt;
run;
%end;
%mend histogram;
Other Misc. Tips and Tricks
See handouts on sign-in table for
Tips and Tricks from SAS