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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

View solution in original post

14 REPLIES 14
Ksharp
Super User

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

CharlotteCain
Quartz | Level 8

Hi,

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

  1. Tea  ii. with sugar    iii. With milk  or iii. Without milk
  2. Tea    ii. without sugar   iii. With milk or iii. Without milk
  3. Coffee ii.  With sugar    iii. With milk  or iii. Without milk
  4. 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

PGStats
Opal | Level 21

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

Cycle Prohibited


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
stat_sas
Ammonite | Level 13

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.

CharlotteCain
Quartz | Level 8

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.

stat_sas
Ammonite | Level 13

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.

Reeza
Super User

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

ballardw
Super User

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

Haikuo
Onyx | Level 15

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

Rick_SAS
SAS Super FREQ

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

Haikuo
Onyx | Level 15

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

CharlotteCain
Quartz | Level 8

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

Rick_SAS
SAS Super FREQ

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

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 14 replies
  • 1077 views
  • 9 likes
  • 8 in conversation