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

Hi Guys,

 

This is my first semester of stats and, consequently, using SAS.  So, I'm sorry for the entry-level question to all you programmers.  Our professor's philosophy is basically "struggle until you figure it out", which is getting incredibly frustrating.

 

So here's my problem.  I need to run a Monte Carlo Simulation where I calculate the sample mean, followed by the population mean, then calculate a 95% confidence interval for each observation, then determine how many times the population mean falls into the 95% confidence interval.

 

We were able to come around to the confidence intervals, although I know this is NOT the preferred, streamlined way of doing so.  But the Proc Univariate statements give us the upper/lower bounds of the confidence intervals.  So now I need the code to calculate each individual confidence interval and then give me the count of how many times the real population mean falls into the confidence interval? 

 

 

1) is there a way to get proc univariate to give me both the upper and lower confidence intervals in a single line?  I basically want to define:

xbar-1.96*sqrt(4/10)<mu<xbar+1.96*sqrt(4/10)   and get the upper/lower bounds of the confidence interval in one function if possible.

 

2) how can I set the data to look at every individual simulation's confidence interval and delete those that *don't* include the number 5 (my calculated population mean)?  I know you can do When = and if statements, but I just can't seem to get anything to work properly.  The only thing I could get out of my professor was "I would use an 'includes' statement" (great, thanks for teaching us that, bro.)

 

I know this is super basic crap, and you guys aren't in the business of teaching people SAS flat out, but if you can point me to some useful resources or useful board posts, that would be very helpful.  No one in this class has experience with this stuff and while we understand the underlying math, getting SAS to spit out the same info seems next to impossible at this point.

We are about at the end of our rope with this.  Thanks so much for your help in advance!

 

data hw3prob1;

seed=2345678;

n=10;

do i=1 to 100000;

      sum=0;

      do k=1 to n;

            x=2+6*ranuni(seed);

            sum=sum+x;

      end;

      xbar=sum/n;

      mu1=xbar-1.96*sqrt(4/10);

      mu2=xbar-1.96*sqrt(4/10);

      output;

end;

proc univariate data=hw3prob1 cibasic(alpha=.05); var mu1;

proc univariate data=hw3prob1 cibasic(alpha=.05); var mu2;

run;

 

data hw3prob1;

set hw3;

if mu1<4.43 then delete;

if mu1>6.68 then delete;

proc freq; table mu1;

run;

 

run;

 

1 ACCEPTED SOLUTION
3 REPLIES 3
Reeza
Super User

I feel like you may be missing some of the key ideas for Monte Carlo simulation. When you talk about an individual, what exactly are you referring to? 

 

Technically, look at PROC MEANS for the statistics. Or use an output dataset from PROC UNIVARIATE. 

 

A good reference paper for simulations is this one:

 

http://www2.sas.com/proceedings/forum2007/183-2007.pdf

 

Proc means data=hw3prob1 n mean std UCLm lclm  NWAY STACKODS;
class K;
var x;
ods output summary=Sim_summary_results;
run;

 

Look at the Sim_Summary_results dataset. 

 

I'm also surprised that a first level stats course is teaching simulation. But I'm guessing this is intended to teach you the CLT. 

 

Rick_SAS
SAS Super FREQ

Use the link that KSharp provides.  Also, you don't need to simulate a normal variate by using the sum of six uniform variates. SAS provides the RAND("Normal") function for generating a random variate from the standard normal distribution. If you want a nonstandard distribution, include the mean and stddev as additional arguments, like this:  

x = rand("Normal", 10, 2); /* population mean=10; popul stddev=2 */

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 14658 views
  • 3 likes
  • 4 in conversation