Fluorite | Level 6

## Generating Sample Means From Uniform Distribution

Hello. I need to take a sample of 10 random numbers from the Uniform(0,1) distribution then calculate the sample mean. I then need to do this 100 times so that I get 100 sample means all from samples of size 10.  Then I need 100 sample means from sample size 100. Then continues on for a total 7 different sample sizes. The resulting data set should have two columns:

1.  The sample size of the sample that the sample mean was calculated from

2. The sample mean

It should have 700 entries. 100 for each sample size. I started with nested for loops but I am stuck on how to calculate the sample mean once I obtain the sample. See code below

data uniform (drop = x);
do n = 10, 100, 200, 500, 1000, 5000, 10000 ;
do i = 1 to 100 ;
do a = 1 to n ;
x = rand('Uniform');
end ;
y = mean(x);                 /* not right.*/
output ;
end;
end;
run ;

I know that this does not work because y = mean(x) will just take the mean of one value- the value of x on the nth loop. I can't figure out how to get the mean of just the sample taken in the third do loop.

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Diamond | Level 26

## Re: Generating Sample Means From Uniform Distribution

You can do this in a data step, you add up all the 10 random numbers and divide by 10.

I would output the individual x values, and then compute the means in PROC SUMMARY

``````proc summary nway data=have;
class n i;
var x;
output out=means mean=x_mean;
run;``````
--
Paige Miller
2 REPLIES 2
Diamond | Level 26

## Re: Generating Sample Means From Uniform Distribution

You can do this in a data step, you add up all the 10 random numbers and divide by 10.

I would output the individual x values, and then compute the means in PROC SUMMARY

``````proc summary nway data=have;
class n i;
var x;
output out=means mean=x_mean;
run;``````
--
Paige Miller
Fluorite | Level 6

## Re: Generating Sample Means From Uniform Distribution

Thanks, I summed and divided in the data step.

data uniform1 (drop = x);
do n = 10, 100, 200, 500, 1000, 5000, 10000 ;
do i = 1 to 100 ;
sumx = 0 ;
do a = 1 to n ;
x = rand('Uniform');
sumx + x ;
meanx = sumx / n ;
end ;
y = meanx ;
output ;
end;
end;
run ;

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