BookmarkSubscribeRSS Feed

Monopoly #2 - Consider "Go-to-Jail" for the Visit Frequency of the Fields

Started ‎02-12-2026 by
Modified ‎03-15-2026 by
Views 124

Overview of the article series of the Monopoly board game simulation in SAS Viya

 

 

Introduction

 

This article extends the work from article Monopoly #1 - Basic Example for the Visit Frequency of the Fields by considering the go-to-jail directive. In the Monoopoly Board Game there are possibilities for going to jail:

  • Landing on the field "go-to-jail"
  • Rolling a Double three times in a row (Note that this rules might not be used in all versions of the game)

Note that the full code is provided in the attached SAS program. In this article only those code elements are explained that differ from the version shown in the article Monopoly #1 - Basic Example for the Visit Frequency of the Fields.

 

1. Considering the "Go-To-Jail" Field

 

1.1 Macro Variable &ConsiderJail

 

In the macro variables an additional macro parameter &ConsiderJail is used.

 

 

%let cnt_players = 5;
%let cnt_games   = 1000;
%let cnt_rounds  = 100;
%let ConsiderJail = yes;
%let Doublet3Jail = no;
%let ConsiderChance = no;
%let seed  = 1;

%let ScenarioName = "2. Consider Jail";
 

1.2 Adding ARRAY "PlayerInJail"

 

In the datastep an additional ARRAY "PlayerInJail" is specified. This ARRAY contains the information whether the respective player currently is in jail.

 

data     work.MNP_Sim1(where=(Round ne 0)) ;

  format Game Round Player Dice1 Dice2 DiceSum 8.;

  ARRAY PlayerPos     {&cnt_players.} PlayerPos1  - PlayerPos&cnt_players. ;
  ARRAY PlayerInJail  {&cnt_players.} PlayerInJail1 - PlayerInJail&cnt_players.;

 

At the beginning of each game, the value for each player is initialized with 0, meaning the the player is not in jail.

 

  do Game = 1 to &cnt_games;

        *** Init-Block;
        Round=0; Dice1=.; Dice2=.; 
        do Player   = 1 to &cnt_players; 
                   PlayerPos[Player]=1; 
                   PlayerInJail[Player]=0;
        end;

 

1.3 Player can only role the dice, if he is not in jail

 

In IF-THEN statement checks, if the player is not in jail.

  • Only then he is allowed to role the dice.
  • If he is in jail his jail counter is reduced by 1

 

             if PlayerInJail[player]=0 then do;

                Dice1 = ceil(rand('Uniform')*6);    
                Dice2 = ceil(rand('Uniform')*6);
                DiceSum = sum(Dice1,Dice2);

                if Dice1 = Dice2 then do; ** First Doublet;
                   output;
                   Dice1 = ceil(rand('Uniform')*6);    
                   Dice2 = ceil(rand('Uniform')*6);
                   DiceSum + sum(Dice1,Dice2);

                   if Dice1 = Dice2 then do; ** Second Doublet;
                      output;
                      Dice1 = ceil(rand('Uniform')*6);    
                      Dice2 = ceil(rand('Uniform')*6);
                      DiceSum + sum(Dice1,Dice2);

                 
                    end; ** Second Doublet;
                end; ** First Doublet;

                    PlayerPos[Player] + DiceSum;
                    PlayerPos[Player] = mod(PlayerPos[Player]-1,40)+1;
              end; 

              else PlayerInJail[player] + (-1);

 

1.4 Considering Go-To-Jail in the program code

 

In the next step the macro parameter &ConsiderJail is evaluated.

  1. If it is YES, the program checks, if after rolling the dice the position where the player lands is "go-to-jail" (field 31 in the classic Monopoly Board Game).
  2. The PlayerInJail value for this player is set to 3, meaning that he has to wait in jail for 3 rounds.

 

                %if %upcase(&ConsiderJail) = YES %then %do;

                  if PlayerPos[Player]=31 then do; 
                        PlayerPos[Player] = 11; *** Go to Jail;
                        PlayerInJail[player]=3;
                  end;                        

                %end; ** Jail;

 

1.5 Set PlayerPos to MISSING when player is in Jail

 

The field visit statistics should only show event where a player lands on a certain field. If the player stays in jail, he position will remain the same also in the next round until he can leave the jail. Therefore the occurrence of the "Jail Field" would be overrepresented by considering not only the "landing" on this field, but also staying at this field. Therefore the PlayerPos value is set to MISSING if the player is already in jail (and did not land there in this round).

 

data work.MNP_Sim1_LastRec;
 set work.MNP_Sim1;
 by Game Round Player;
 drop dice1 dice2 dicesum;
  *** Set Location to MISSING, if Player is in Jail to avoid double/triple counting;
  ARRAY PlayerPos     {&cnt_players.} PlayerPos1  - PlayerPos&cnt_players. ;
  ARRAY PlayerInJail  {&cnt_players.} PlayerInJail1 - PlayerInJail&cnt_players.;
  do Player = 1 to &cnt_players;
   if PlayerInJail[Player] then PlayerPos[Player]=.;
  end;
  *** Keep only last record per round;
  if last.round then output;
run;

 

1.7 Histogram for the Visit Distribution

 

proc sgplot data=work.player_location;
 title Scenario: &scenarioname.;
 histogram value / binstart=1 binwidth=1;
 yaxis max = 6 label = "Proportion of Visits (%)";
 xaxis label = "Field Number";
run;
title;

 

When you plot the visit distribution using the SGPLOT procedure, you see the following results.

  • The visit frequency of the "Jail" field is higher. It roughly doubled is frequency, because the visitors from the "Go-to-Jail" field get sent here.
  • The frequency of the "go-to-jail" field is 0, as nobody is allowed to stay there.
  • The frequency of the fields after the "Jail" fields is higher, as player are leaving from this field more often than from other fields. Consequently you see that the visit frequency for field "Go-to-Jail" is lower as these fields to not get visitors how come from the "Go-to-jail" fields.

 

Monopoly_JailYES.png

 

 

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Video for Section 1

 

The following video has been recorded for the SAS ask-the-expert session on Monopoly simulations which I used to talk about them in the session. 

 

Video 1 shows the code described in section 1.1 to 1.7

 

(view in My Videos)
 

2. Considering the "Go To Jail after rolling three doubles" directive

 

2.1 Changes to the Code

 
The macro variable "Doublet3Jail" is set to YES for this scenario.
 
%let ConsiderJail = yes;
%let Doublet3Jail = yes;
%let ConsiderChance = no;

%let seed  = 1;
%let ScenarioName = "3. Consider Jail and 3Doublet";
 
In order to consider "go-to-jail" after rolling three doubles the following change to the code is made. Note that only the relevant part of the code is shown here. The attached SAS Program contains the full code.
 

                if Dice1 = Dice2 then do; ** First Doublet;
                   output;
                   Dice1 = ceil(rand('Uniform')*6);    
                   Dice2 = ceil(rand('Uniform')*6);
                   DiceSum + sum(Dice1,Dice2);

                   if Dice1 = Dice2 then do; ** Second Doublet;
                      output;
                      Dice1 = ceil(rand('Uniform')*6);    
                      Dice2 = ceil(rand('Uniform')*6);
                      DiceSum + sum(Dice1,Dice2);

                    %if %upcase(&doublet3jail.) = YES %then %do;
                      if Dice1 = Dice2 then do; ** Third Doublet;
                         PlayerInJail[player]=3;
                         PlayerPos[Player]=31;
                      end; ** Third Doublet;
                    %end;
                 
                    end; ** Second Doublet;
                end; ** First Doublet;

If a third doublet in a row is roled by the player and the Doublet3Jail macro parameter is set to YES, the player is sent to jail. 
 
The token is only moved forward if the player was not just sent to jail
 
                if PlayerInJail[player] ne 3 then do; ** was just sent to jail, do not move forward;
                    PlayerPos[Player] + DiceSum;
                    PlayerPos[Player] = mod(PlayerPos[Player]-1,40)+1;
                end; ** PlayerJail Check = 0;
              end; 

              else PlayerInJail[player] + (-1);

 

2.2 Visualizing the results

 
When plotting the histogram after this scenario you see that the height of the Jail-Field slightly increased as now more turns end at the jail field.
 
Monopoly_JailYES and Double.png
 

Video for Section 2

 

The following video has been recorded for the SAS ask-the-expert session on Monopoly simulations which I used to talk about them in the session. 

 

Video 2 shows the code described in section 2.1 to 2.2

 
(view in My Videos)

 

 

Related Articles and Links

 

 
Youtube:

 

Contributors
Version history
Last update:
‎03-15-2026 03:15 PM
Updated by:

Catch up on SAS Innovate 2026

Dive into keynotes, announcements and breakthroughs on demand.

Explore Now →

SAS AI and Machine Learning Courses

The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.

Get started

Article Tags