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

SAS 2.png

 

This is what I have so far.

Data roll;
MyMoney=100;
	Die1 = ceil(6*ranuni(-1));
	Die2 = ceil(6*ranuni(-1));
sum = Die1+Die2;
if sum > 9 then MyMoney + 5;
else if sum < 9 then MyMoney - 2.50;


Run;

proc print data=roll;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

How about something like this?

 

 

 

data RandInt;
length die1 8 die2 8 winnings 8 balance 8;
/* streaminit for reproducible sequence, comment out for different results */
call streaminit(123); 
retain balance 100;
do i = 1 to 100;
   die1 = rand("Integer", 1, 6);  /* requires SAS 9.4M5 or later */
   die2 = rand("Integer", 1, 6);  
   winnings = ifn(die1+die2>=9,5,-2.50);
   balance+winnings;
   output;
end;
drop i;
run;

 

 

ChrisHemedinger_0-1634249030927.png

 

Edit:

At first I had payout when the total > 9 only, and that's a sucker's game. But corrected to >= 9 and it seems better.

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

Are you asking for help?

--
Paige Miller
ChrisHemedinger
Community Manager

How about something like this?

 

 

 

data RandInt;
length die1 8 die2 8 winnings 8 balance 8;
/* streaminit for reproducible sequence, comment out for different results */
call streaminit(123); 
retain balance 100;
do i = 1 to 100;
   die1 = rand("Integer", 1, 6);  /* requires SAS 9.4M5 or later */
   die2 = rand("Integer", 1, 6);  
   winnings = ifn(die1+die2>=9,5,-2.50);
   balance+winnings;
   output;
end;
drop i;
run;

 

 

ChrisHemedinger_0-1634249030927.png

 

Edit:

At first I had payout when the total > 9 only, and that's a sucker's game. But corrected to >= 9 and it seems better.

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
ballardw
Super User

Still a suckers game or at least not not for me.

Expected winnings per play, assuming fair dice, is -$0.41666666...

If you end up with more than 58.3333.... at the end of 100 plays you beat the house (a bit).

ballardw
Super User

@Godzilla_Hat wrote:

SAS 2.png


Why did you call this a "coin flip"? There are more than two outcomes per die and coins, barring the "lands on edge" event typically have only 2 outcomes.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1488 views
  • 0 likes
  • 4 in conversation