- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Find the simulated probability that the mean is between 2 and 3.
- Find the mean of the means.
- Find the standard deviation of the means.
- 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).
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Why?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Do a proc contents of
proc contents data=p197_24;
ods select variables;
run;
Now see if that variable is listed or not
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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 😞
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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