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.
@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;
@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;
Would anyone be willing to explain to me why the "mean=" at the end is necessary? I had to do basically this on an assignment. Without the mean=, it gave me 3000 results instead of 600. I tried searching the SAS documentation for an explanation and couldn't find anything useful...
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.