BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Michaelcwang2
Obsidian | Level 7

I'm trying to come out a series of normal distribution and tested by Shapiro-Wilks test. The code is as below:

DATA RAND;
DO J=0 TO 9;
    CALL STREAMINIT(123);
        DO i=1 to 50;
	    X=Rand("normal",1.5+0.001*j,0.3);
	    OUTPUT;
	    END;
		    
END;
RUN;	    
/*************************************************
*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=RAND, vars=X, output=Normality);

But the output data set is only one item by one Varname X from 500 data, not for j between 0 and 9 and from 50 data. Thank you if you can support.

1 ACCEPTED SOLUTION

Accepted Solutions
stat_sas
Ammonite | Level 13

Hi,

 

A small change in your macro code will generate the desired results. Just add by statement in proc univariate.

 

proc univariate data = &input normal;

var &vars;

by j; run;

 

View solution in original post

2 REPLIES 2
stat_sas
Ammonite | Level 13

Hi,

 

A small change in your macro code will generate the desired results. Just add by statement in proc univariate.

 

proc univariate data = &input normal;

var &vars;

by j; run;

 

Michaelcwang2
Obsidian | Level 7
Yes, it works and highly appreciated!

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1888 views
  • 0 likes
  • 2 in conversation