Turn on suggestions

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

Showing results for

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

Options

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

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 03-20-2018 09:05 AM
(1526 views)

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

2 REPLIES 2

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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 ;

**Available on demand!**

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

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.