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

SO I'm new to SAS and I've been working on this HW assignment for 5 hours.

 

Generate 200 samples of size 4000 random numbers from Uniform distribution with parameters a = -4, b = 6. For each of these 200 samples calculate the mean.

 

  1. Find the simulated probability that the mean is between 2 and 3.
  2. Find the mean of the means.
  3. Find the standard deviation of the means.
  4. Draw the histogram of the means.

Here's what I have so far:

 

data Prob1A;
call streaminit (0);
k= 200;
n= 4000;
do i=1 to k;
	xuni= rand('uniform', -4, 6);
	output;
keep xuni; 
end;
proc means data=Prob1A noprint;
by SampleID;
var xuni;
output out=1Ameans mean=SampleMean std=SampleStd;
run;
data p197_24;
set 1Ameans;
A1sol = (2< SampleMean < 3);
run;
proc freq data= p197_24;
tables A1sol;
run;

Honestly I'm ready to scream and throw my computer out the window. I've tried seeking help, but have not been successful yet. PLEASE HELP (I might be out a $1000 laptop soon).

1 ACCEPTED SOLUTION

Accepted Solutions
valarievil
Obsidian | Level 7

Thanks for your responses! here is the correct code I made with your advice:

 

data Prob1A;
call streaminit (47);
k= 2000;
n= 40000;
do sampleid=1 to k;
 do j=1 to n;
	xuni= rand('uniform', -6, 10);
	output;
 end;
end;
keep sampleid xuni; 
run;
proc means data=Prob1A noprint;
by SampleID;
var xuni;
output out=A1means mean=SampleMean std=SampleStd;
run;
data p197_24;
set A1means;
A1sol = (1.97< SampleMean < 2.4);
run;
proc freq data= p197_24;
tables A1sol;
run;
/**1B******1C**************************************/
proc means data=A1means;
run;
/************1D**************************************/
ods select Moments Histogram;
proc univariate data=A1means;
label SampleMean = "Sample Mean of U(-6,10) Data";
var SampleMean;
histogram SampleMean; 
run;

Sorry the parameters are a bit different than the original

View solution in original post

9 REPLIES 9
novinosrin
Tourmaline | Level 20

Hi @valarievil   Let's first get your sampling corrected. Then using the corrected sample, you can do the rest easily as those are merely copy/paste

 

Please follow the comments:

 


data Prob1A;
call streaminit (1234567);
k= 200;/*no of samples*/
n= 4000;/*sample size*/
do sampleid=1 to k; /*200 repetitions*/
 do j=1 to n;/*1 to sample size*/ 
	xuni= rand('uniform', -4, 6);
	output;
 end;
end;
keep sampleid xuni; 
run;

Now, using the above try the rest

valarievil
Obsidian | Level 7
I keep getting the error "Variable A1SOL not found."
Why?
novinosrin
Tourmaline | Level 20

Do a proc contents of 

 


proc contents data=p197_24;

ods select variables;

run;

 

 

Now see if that variable is listed or not

 

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

yes dupe thread.  

start with replacing your first data step with something like this

 

data Prob1A;
retain SampleID 0;
call streaminit (0);
k= 200;
n= 4000;
do b = 1 to 10;
do i=1 to k;
	SampleID =b +1;
	xuni= rand('uniform', -6, 10);
	output;
keep xuni SampleID; 
end;
end;
run;

You first of all need SampleID on the dataset.

valarievil
Obsidian | Level 7
What is the significance of the line "do b= 1 to 10"?
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

you need a variable named SampleID that you call in your next proc means because of the by statement.

At the same time you will need to sort the dataset because of that by statement in the proc means in order for proc means to work.

 

 

PaigeMiller
Diamond | Level 26

Hello @valarievil you do not want to post the same question twice. This is not a good thing to do. Please everyone reply to at the other thread at https://communities.sas.com/t5/SAS-Programming/Probability-that-the-sample-means-are-between-2-and-3... where I have pointed out a likely cause of your trouble.

--
Paige Miller
novinosrin
Tourmaline | Level 20

Oh well, I didn't know this is a duplicate thread. Oops.   @valarievil, relax and do not panic about HW. I would just request you to keep it one thread. Nothing wrong in asking over and over but duplicating is not needed as it causes confusion.  But we have given you a head start, try and message back. Cheers!

 

PS Do not break your laptop 🙂 I have done that. It's one my deepest regret 😞

valarievil
Obsidian | Level 7

Thanks for your responses! here is the correct code I made with your advice:

 

data Prob1A;
call streaminit (47);
k= 2000;
n= 40000;
do sampleid=1 to k;
 do j=1 to n;
	xuni= rand('uniform', -6, 10);
	output;
 end;
end;
keep sampleid xuni; 
run;
proc means data=Prob1A noprint;
by SampleID;
var xuni;
output out=A1means mean=SampleMean std=SampleStd;
run;
data p197_24;
set A1means;
A1sol = (1.97< SampleMean < 2.4);
run;
proc freq data= p197_24;
tables A1sol;
run;
/**1B******1C**************************************/
proc means data=A1means;
run;
/************1D**************************************/
ods select Moments Histogram;
proc univariate data=A1means;
label SampleMean = "Sample Mean of U(-6,10) Data";
var SampleMean;
histogram SampleMean; 
run;

Sorry the parameters are a bit different than the original

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 9 replies
  • 1124 views
  • 2 likes
  • 4 in conversation