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;
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.
Calling @Rick_SAS
@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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.