I'm looking for some SAS code that will compute the probability of one value (randomly taken from a normal distribution) being greater than another value (randomly taken from a another normal distribution) given the means and standard deviations of both distributions are known. Thank you


If this is a question of implementation, then perhaps this R code can help you in some way, since I do not have SAS:

n <- 10000000
mean1 <- 1; var1 <- 3
mean2 <- 0; var2 <- 1 # defining parameters

X <- rnorm(n, mean = mean1, sd = sqrt(var1))
Y <- rnorm(n, mean = mean2, sd = sqrt(var2)) #generating random variables

Z <- (X<=Y) #creates logical vector
sum(Z) / length(Z) #I get about 0.308669

Or perhaps you find it easier to use that linear transformations of normal random variables are again normal and use a built in function? For example, if

$$ X \sim N(\mu_1,\sigma_1^2) \text{ and } Y \sim N(\mu_2, \sigma_2^2) \quad \Longrightarrow \quad X \pm Y \sim N(\mu_1 \pm \mu_2, \sigma_1^2 + \sigma_2^2), $$

then $$ P(X \leq Y) = P(X-Y \leq 0) = P\left(\frac{(X-Y)-(\mu_1-\mu_2)}{\sigma_1 + \sigma_2} \leq \frac{-(\mu_1-\mu_2)}{\sigma_1 + \sigma_2} \right) = \Phi \left( \frac{-(\mu_1-\mu_2)}{\sigma_1 + \sigma_2} \right), $$

where $\Phi(\cdot)$ is the cumulative distribution function for the standard normal distribution and we get the following in R (which is nicer):

pnorm(-(mean1-mean2)/sqrt(var1+var2) #I get about 0.308538

I hope this helps with your implementation, please report back.

  • $\begingroup$ This worked great! thanks! $\endgroup$ Jun 27 '19 at 14:41
  • 1
    $\begingroup$ You are welcome, if this answers your question, you should then close it. $\endgroup$
    – K. Brix
    Jun 28 '19 at 8:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.