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
- /
- General Programming
- /
- SAS Datastep code example for probablility calcula...

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

11-10-2014 08:30 AM

Hi Folks,

Can anybody provide me a simple SAS datastep algorithm for the below question and a statistical explanation for my understanding please

If I have a decision to make **how do I calculate the probability** of a selection how does one calculate the probability?

For example: What is the probability of me selecting Tea – with sugar – with milk.

What is the formula? 0.5 x 0.5 x 0.5

Accepted Solutions

Solution

11-10-2014
01:44 PM

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

11-10-2014 01:44 PM

This is a better question for CrossValidated than here.

P(Tea, sugar, milk)= p(tea)*p(sugar)*p(milk)=0.5*0.5*0.5=1/8

Each odd is 0.5 because there are two options

i.e. choices are tea or coffee so p(tea)=1/2=0.5

and the same logic applies for remaining ingredients.

Another way to calculate this is to list all the possible combinations and see how many times you get your output:

1 out of 8 possible combinations:

**Tea|Sugar|Milk**

Tea|Sugar|No Milk

Tea|No Sugar|Milk

Tea|No Sugar|No Milk

Coffee|Sugar|Milk

Coffee|Sugar|No Milk

Coffee|No Sugar|Milk

Coffee|No Sugar|No Milk

All Replies

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

11-10-2014 09:30 AM

Sorry. I couldn't see that picture. Maybe it is being block by China.

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

11-10-2014 10:36 AM

Hi,

First off, I **apologise** for that coz it aint opening. Well the picture depicts as follows:

- Tea ii. with sugar iii. With milk or iii. Without milk
- Tea ii. without sugar iii. With milk or iii. Without milk
- Coffee ii. With sugar iii. With milk or iii. Without milk
- Coffee ii. Without sugar iii. With milk or iii. Without milk

Wish I could get the pic to work, but that's exactly the information.

Hope you are well.

Thanks so much,

Charlotte

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

11-10-2014 09:48 AM

I can't see the picture either. I get the message

**Description: Could not process your request for the document because it would cause an HTTP proxy cycle. Please check the URL and your browser's proxy settings.**

PG

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

11-10-2014 12:52 PM

Hi,

Probability selecting Tea – with sugar – with milk is

0.5 x 0.5 x 0.5

Which is aleardy mentioned above in your question.

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

11-10-2014 01:32 PM

Well, i noticed that. I'm not understanding the logic though or may be I'm having a blonde moment. lol. I thought it would be 0.5*0.25*0.25*0.25*0.25. I still would like you to explain me the formula if you don't mind.

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

11-10-2014 01:41 PM

Sure, tea – with sugar – with milk are 3 independent events each having two possible outcomes. In the given scenario with sugar has prob=0.5, with sugar prob=0.5 and with milk prob=0.5. In the next step we just need to multiply them.

Solution

11-10-2014
01:44 PM

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

11-10-2014 01:44 PM

This is a better question for CrossValidated than here.

P(Tea, sugar, milk)= p(tea)*p(sugar)*p(milk)=0.5*0.5*0.5=1/8

Each odd is 0.5 because there are two options

i.e. choices are tea or coffee so p(tea)=1/2=0.5

and the same logic applies for remaining ingredients.

Another way to calculate this is to list all the possible combinations and see how many times you get your output:

1 out of 8 possible combinations:

**Tea|Sugar|Milk**

Tea|Sugar|No Milk

Tea|No Sugar|Milk

Tea|No Sugar|No Milk

Coffee|Sugar|Milk

Coffee|Sugar|No Milk

Coffee|No Sugar|Milk

Coffee|No Sugar|No Milk

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

11-10-2014 03:50 PM

Pedantic note: Assumes the probabilities of the choices are independent.

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

11-10-2014 04:04 PM

True

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

11-10-2014 04:52 PM

SAS has a function for it:

**data** _null_;

p=**0.5**; /*is a numeric probability of success parameter, the success rate of each test*/

n=**3**; /*is an integer number of independent Bernoulli trials parameter: the total number of the tests*/

m=**3**;

/*is an integer number of successes random variable: the number of successful test, in your case,

the m is the Maximum: n, as the probability of one success in one trial is the same as all success in all trials*/

prob=PROBBNML(p,n,m)- PROBBNML(p,n,m-**1**);

put prob=;

**run**;

Haikuo

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

11-10-2014 08:21 PM

Or use the CDF function. The following statements are equivalent:

prob=PROBBNML(p,n,m) - PROBBNML(p,n,m-1);

prob2 = cdf("Binomial",m,p,n) - cdf("Binomial",m-1,p,n);

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

11-10-2014 08:37 PM

Thanks for sharing, Rick! CDF function is obviously much more powerful.

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

11-10-2014 11:54 PM

Hi Haikuo and Rick,Thank you so much for the Genius help. I can't appreciate enough. Anyways, did you memorise SAS functions or you developed a knack to quickly search for the right now? I am asking this coz your inputs will only help me learn faster.

Cheers,

Charlotte

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

11-11-2014 01:11 PM

SAS is big. I don't pretend to know it all, but I've taken the time to learn about the functions that I use over and over. CDF is one of those functions. If you do a lot with univariate distributions in SAS, read this article: Four essential functions for statistical programmers - The DO Loop