SAS Macro : Test for Normal Distribution

Deepanshu Bhalla 2 Comments

In most of the statistical tests, you need check assumption of normality. There is a test called Shapiro-Wilk W test that can be used to check normal distribution. If the p-value is greater than .05, it means we cannot reject the null hypothesis that a variable is normally distributed.

SAS Macro for Normality

The following SAS macro performs a test for normality on the variables X1 and X2 in the dataset "test". It uses the Shapiro-Wilk test and assigns a "Normal" or "Non-normal" status to each variable based on the p-value of the test.

/*************************************************
*input = dataset to check;
*vars = Specify variable(s) for which you want to check normality;
*output = dataset to output with normality status;
**************************************************/

%macro normal(input=, vars=, output=);

ods output TestsForNormality = Normal;
proc univariate data = &input normal;
var &vars;
run;
ods output close;

data &output;
set Normal ( where = (Test = 'Shapiro-Wilk'));
if pValue > 0.05 then Status ="Normal";
else Status = "Non-normal";
drop TestLab Stat pType pSign;
run;
%mend;

%normal(input=test, vars=X1 X2, output=Normality);
Related Posts
Spread the Word!
Share
About Author:
Deepanshu Bhalla

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has over 10 years of experience in data science. During his tenure, he worked with global clients in various domains like Banking, Insurance, Private Equity, Telecom and HR.

2 Responses to "SAS Macro : Test for Normal Distribution"
  1. Thank you for posting very useful tips! I found your website perfect for my needs.I always like your article because you have provide every time informative post..Thanks!

    ReplyDelete
  2. Thanks for every other fantastic post. Where else could anybody get that type of information in such a perfect method of writing?

    ReplyDelete
Next → ← Prev