/*correct average score by scores of the subsequent throws*/
/*uses score_stat from dice1.sas*/
/*
This software is not designed or intended for use in on-line control of
aircraft, air traffic, aircraft navigation or aircraft communications; or in
the design, construction, operation or maintenance of any nuclear
facility. Licensee represents and warrants that it will not use or
redistribute the Software for such purposes.

(c) Jaroslav Pulpan JPS s.r.o.
    when in SAS Institute Prague  2001
*/
ods html body="c:\temp\iml-output.htm" style=theme;
title "IML procedure output";
proc iml;
  p0=j(6,1,0);
  p=j(6,6,0);
  s=j(6,6,0);
   use score_stat (where=(k=8 or k between 1 and 6)) ;
   do data;
	  read  next var {i k pik avgscore};
      if (k = 8) then do;
          p0[i]=pik;
        end;
      else if ( k < 7 ) then do;
        p[i,k]=pik;
        s[i,k]=avgscore;
       end;
   end;
   reset autoname;
   print p p0,s;

   b=-(p#s)[,+];
   a=p-i(6);
   print a b;
   w=solve(a,b);
   print w;
   cs=w#((j(6,1,1)-p0)/p0);
   print cs;
/*   save w and CS to dataset to be HTMLed nicely by proc report*/
    I=(1:6)`;
    create w_cs var{I W Cs};
    append ;
run;

ods html close;

ods html body="c:\temp\Table2.htm" style=theme;

title "Table 2: W(I) - Average scores accumulated until throw";
title2 "with zero score and critical scores Cs(I) for stopping ";
footnote "Stop throwing if your current score is above Cs(I) ";
footnote2 " and you deciding with I dice in hand";

proc report data=w_cs nowd 
	style(report)=[font_face=verdana font_size=1 ]
	style(header)=[font_face=verdana font_size=1]
	style(column)=[font_face=verdana font_size=1 just=right]
;
	define i/"I=Inital /number /of dice" display;
	define w/"W(I)=Average /score gain" format=comma12.2;
	define CS/"Cs(I)=critical /score for/stopping" format=comma12.2;
run;
ods html close;