BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
UCFtigers2017
Fluorite | Level 6

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
PaigeMiller
Diamond | Level 26

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

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

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
UCFtigers2017
Fluorite | Level 6

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 ;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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