Task

Solve a partially filled-in normal   9x9   Sudoku grid   and display the result in a human-readable format.

references

 Algorithmics of Sudoku   may help implement this.
 Python Sudoku Solver Computerphile video.


/* define SAS data set */
data Indata;
   input C1-C9;
   datalines;
. . 5 . . 7 . . 1
. 7 . . 9 . . 3 .
. . . 6 . . . . .
. . 3 . . 1 . . 5
. 9 . . 8 . . 2 .
1 . . 2 . . 4 . .
. . 2 . . 6 . . 9
. . . . 4 . . 8 .
8 . . 1 . . 5 . .
;
 
/* call OPTMODEL procedure in SAS/OR */
proc optmodel;
   /* declare variables */
   set ROWS = 1..9;
   set COLS = ROWS;
   var X {ROWS, COLS} >= 1 <= 9 integer;
 
   /* declare nine row constraints */
   con RowCon {i in ROWS}:
      alldiff({j in COLS} X[i,j]);
 
   /* declare nine column constraints */
   con ColCon {j in COLS}:
      alldiff({i in ROWS} X[i,j]);
 
   /* declare nine 3x3 block constraints */
   con BlockCon {s in 0..2, t in 0..2}:
      alldiff({i in 3*s+1..3*s+3, j in 3*t+1..3*t+3} X[i,j]);
 
   /* fix variables to cell values */
   /* X[i,j] = c[i,j] if c[i,j] is not missing */
   num c {ROWS, COLS};
   read data indata into [_N_] {j in COLS} <c[_N_,j]=col('C'||j)>;
   for {i in ROWS, j in COLS: c[i,j] ne .}
      fix X[i,j] = c[i,j];
 
   /* call CLP solver */
   solve;
 
   /* print solution */
   print X;
quit;