turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- 95% confidence intervals with monte carlo simulati...

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

10-17-2016 07:36 PM

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**;

Accepted Solutions

Solution

10-18-2016
03:13 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to abjmorrison

10-18-2016 01:11 AM

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to abjmorrison

10-18-2016 12:08 AM

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.

Solution

10-18-2016
03:13 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to abjmorrison

10-18-2016 01:11 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to abjmorrison

10-18-2016 11:23 AM

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 */