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
- /
- Simulating Data from Standard Normal 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 04-23-2019 04:11 PM
(2355 views)

First I create a 100 obs dataset with a DO...End loop with the variable x. And then I use another DO loop of 600

rounds to generate a total of 600 samples, 100 obs each. And then I use a proc means step to calculate the sample mean of x for each sample. So my goal is to have a total of 600 sample means (Each sample containing 100 obs) and then find out the mean of these sample means.

Here is my code:

```
data sample(keep=X);
call streaminit(123);
do j=1 to 600;
do i=1 to 100;
X = rand("Normal");
output;
end;
end;
run;
proc means data=sample;
run;
```

I get a total of 60,000 observations but want 600 sample means. The proc means statement gives the mean for all 60,000 obs.

1 ACCEPTED SOLUTION

Accepted Solutions

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

@ddpatel wrote:

First I create a 100 obs dataset with a DO...End loop with the variable x. And then I use another DO loop of 600rounds to generate a total of 600 samples, 100 obs each. And then I use a proc means step to calculate the sample mean of x for each sample. So my goal is to have a total of 600 sample means (Each sample containing 100 obs) and then find out the mean of these sample means.Here is my code:`data sample(keep=X); call streaminit(123); do j=1 to 600; do i=1 to 100; X = rand("Normal"); output; end; end; run; proc means data=sample; run;`

I get a total of 60,000 observations but want 600 sample means. The proc means statement gives the mean for all 60,000 obs.

Use this code to get a mean for each of the 600 values of j.

```
data sample;
call streaminit(123);
do j=1 to 600;
do i=1 to 100;
X = rand("Normal");
output;
end;
end;
run;
proc summary data=sample nway;
class j;
var x;
output out=want mean=;
run;
```

--

Paige Miller

Paige Miller

3 REPLIES 3

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

@ddpatel wrote:

First I create a 100 obs dataset with a DO...End loop with the variable x. And then I use another DO loop of 600rounds to generate a total of 600 samples, 100 obs each. And then I use a proc means step to calculate the sample mean of x for each sample. So my goal is to have a total of 600 sample means (Each sample containing 100 obs) and then find out the mean of these sample means.Here is my code:`data sample(keep=X); call streaminit(123); do j=1 to 600; do i=1 to 100; X = rand("Normal"); output; end; end; run; proc means data=sample; run;`

I get a total of 60,000 observations but want 600 sample means. The proc means statement gives the mean for all 60,000 obs.

Use this code to get a mean for each of the 600 values of j.

```
data sample;
call streaminit(123);
do j=1 to 600;
do i=1 to 100;
X = rand("Normal");
output;
end;
end;
run;
proc summary data=sample nway;
class j;
var x;
output out=want mean=;
run;
```

--

Paige Miller

Paige Miller

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

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

The OUTPUT statement requests the statistics that you want to save in the output data set. In this case, you are requesting the mean statistic for each j, where j=1..600.

You might be more familiar with PROC MEANS than PROC SUMMARY. If so, here is an equivalent way to produce the 600 sample means:

```
proc means data=sample noprint;
by j;
var x;
output out=want mean=;
run;
```

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. **Registration is now open through August 30th**. Visit the SAS Hackathon homepage.

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.