Online File

How to use this page


Rick Aster: Professional SAS Programming Secrets: Contents

Chapter 12
Program 12g
Exhaustive simulation of dice


*
  Professional SAS Programming Secrets
  Program 12g
  Exhaustive simulation of dice
*;

data work.dice2 (keep=result n percent);
   array counts{3} adv_1 tie adv_2;
   array names{3} $ 5 _temporary_ ('Adv 1', 'Tie  ', 'Adv 2');

   *
      Generate 2 dice per player and compare totals. Count results.
   *;
   do player1_die1 = 1 to 6;
      do player1_die2 = 1 to 6;
         player1_dice_total = player1_die1 + player1_die2;
         do player2_die1 = 1 to 6;
            do player2_die2 = 1 to 6;
               player2_dice_total = player2_die1 + player2_die2;
               select ;
                  when (player1_dice_total > player2_dice_total)
                      adv_1 + 1;
                  when (player2_dice_total > player1_dice_total)
                      adv_2 + 1;
                  otherwise tie + 1;
                  end;
               end;
            end;
         end;
      end;

   *
     Save results.
   *;
   n_total = adv_1 + tie + adv_2;
   do i = 1 to 3;
      result = names{i};
      n = counts{i};
      percent = n/n_total*100;
      output;
      end;
run;
proc print data=work.dice2 noobs;
run;

 O /\

Global
Statements

RICK ASTER

SAS

BOOKS

Tech | Dictionary

Download | Rastinate

Rick Aster

Professional SAS Programming Secrets

Contents/Online Files

Corrections