Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- General Programming
- /
- Generating Sample Means From Uniform Distribution

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

03-20-2018 09:05 AM

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.

Accepted Solutions

Solution

03-20-2018
10:07 AM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to UCFtigers2017

03-20-2018 09:09 AM

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

Paige Miller

All Replies

Solution

03-20-2018
10:07 AM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to UCFtigers2017

03-20-2018 09:09 AM

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

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to PaigeMiller

03-20-2018 10:27 AM

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 ;