BookmarkSubscribeRSS Feed
Fara_I
Fluorite | Level 6

I have the following code that simulates the 36 possible outcomes of throwing two six-sided dice, but I wanted to know if there is a SAS command that will tell me that the probability of any one throw is 1/36 or approximately 2.78%? Thank you in advance for any help you can provide me!

 

Here is the code: 

data auto;
do D1= 1 to 6;
do D2= 1 to 6;
X = sum(D1, D2);
output;
end;
end;

3 REPLIES 3
s_lassen
Meteorite | Level 14

The short answer is: there is not. If you want the probabilities for each result, try something like this:

data prob;
  array prob(2:12) prob2-prob12;
  do d1=1 to 6;
    do d2=1 to 6;
      prob(d1+d2)+1/36;
      end;
   end;
  drop d1 d2;
run;

But if you just want the probability for each throw, it is 1/(6**2)=1/36. I do not think there is a special function for that.

ballardw
Super User

@Fara_I wrote:

I have the following code that simulates the 36 possible outcomes of throwing two six-sided dice, but I wanted to know if there is a SAS command that will tell me that the probability of any one throw is 1/36 or approximately 2.78%? Thank you in advance for any help you can provide me!

 

Here is the code: 

data auto;
do D1= 1 to 6;
do D2= 1 to 6;
X = sum(D1, D2);
output;
end;
end;


proc freq data=auto;
   table x;
run;

With display, by default, the percent of the distribution points of the X variable. That "Percent" would also be the probability distribution of X, barring rounding error. You can send the output to a data set.

 

If you want the distribution of each possible die toss then you need to create an ordered pair such as:

data auto;
   do D1= 1 to 6;
      do D2= 1 to 6;
         X = sum(D1, D2);
         y = cats(d1,d2);
         output;
      end;
   end;
run;

proc freq data=auto;
   table x y;
run;

And proc freq again shows the percent, or probability, of each ordered pair.

 

For any given PERMUTATION of items the probability is basically 1/(n1*n2*n3*…*nx) where each n is the number of possibilities for that position. Simple 6-sided die the N is always 6 so the probability of any given ordered pair is 1/(6^n) for any given number of dice. 6^n is 6 to the nth power.

 

Combinatorics is somewhat fun, but I'm possibly warped.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 3 replies
  • 2684 views
  • 1 like
  • 4 in conversation