BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
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;



do i=1 to 100000;


      do k=1 to n;









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

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



data hw3prob1;

set hw3;

if mu1<4.43 then delete;

if mu1>6.68 then delete;

proc freq; table mu1;





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:


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


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. 



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



Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg



Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 3 replies
  • 4 in conversation