Presented by: Steve First 2997 Yarmouth Greenway Drive, Madison, WI Phone: (608) Web:

Similar documents
An Introduction to SAS Macros

Introduction to PROC SQL

Arrays Made Easy: An Introduction to Arrays and Array Processing

Standardize Your Data Preparation in SAS: Use SQL! May Yarmouth Greenway Drive Madison, WI (608)

Developing a Dashboard to Aid in Effective Project Management

2997 Yarmouth Greenway Drive, Madison, WI Phone: (608) Web:

PROC FORMAT Tips. Rosalind Gusinow 2997 Yarmouth Greenway Drive u Madison, WI (608) u

A Plot & a Table per Page Times Hundreds in a Single PDF file

INTRODUCTION TO THE SAS ANNOTATE FACILITY

Innovative Graph for Comparing Central Tendencies and Spread at a Glance

Choosing the Right Tool from Your SAS and Microsoft Excel Tool Belt

Creating Maps in SAS/GRAPH

Generating Participant Specific Figures Using SAS Graphic Procedures Carry Croghan and Marsha Morgan, EPA, Research Triangle Park, NC

PharmaSUG Paper TT10 Creating a Customized Graph for Adverse Event Incidence and Duration Sanjiv Ramalingam, Octagon Research Solutions Inc.

ODS LAYOUT is Like an Onion

Figure 1. Paper Ring Charts. David Corliss, Marketing Associates, Bloomfield Hills, MI

USING SAS PROC GREPLAY WITH ANNOTATE DATA SETS FOR EFFECTIVE MULTI-PANEL GRAPHICS Walter T. Morgan, R. J. Reynolds Tobacco Company ABSTRACT

Chapter 3. Advanced Techniques. The advanced techniques presented in this chapter are meant to solve difficult grids.

Using Enterprise Guide Effectively. BI Tom Miron Systems Seminar Consultants, Madison, WI

Displaying Multiple Graphs to Quickly Assess Patient Data Trends

A Juxtaposition of Tables and Graphs Using SAS /GRAPH Procedures

It s Not All Relative: SAS/Graph Annotate Coordinate Systems

Top Award and First Place Best Presentation of Data Lan Tran-La. Scios Nova, Inc. BLOOD PRESSURE AND HEART RATE vs TIME

BI-09 Using Enterprise Guide Effectively Tom Miron, Systems Seminar Consultants, Madison, WI

Using ANNOTATE MACROS as Shortcuts

Using SAS/GRAPH Software to Analyze Student Study Habits. Bill Wallace Computing Services University of Saskatchewan

David Beam, Systems Seminar Consultants, Inc., Madison, WI

Create Flowcharts Using Annotate Facility. Priya Saradha & Gurubaran Veeravel

* builds the RGB color string from the color. * reads the red, green; and blue values for. * constructs an ANNOTATE dataset by

Taming the Box Plot. Sanjiv Ramalingam, Octagon Research Solutions, Inc., Wayne, PA

Base and Advance SAS

Advanced Macro Topics Steven First, Systems Seminar Consultants, Madison, WI

Data Annotations in Clinical Trial Graphs Sudhir Singh, i3 Statprobe, Cary, NC

Demystifying Inherited Programs

A Sudoku Solver (1A) Richard Bird Implementation. Young Won Lim 11/15/16

Annotate Dictionary CHAPTER 11

Fly over, drill down, and explore

Parallelizing SAT Solver With specific application on solving Sudoku Puzzles

SAS Enterprise Guide. Kathleen Nosal Yarmouth Greenway Drive Madison, WI (608)

MANAGING SAS/GRAPH DISPLAYS WITH THE GREPLAY PROCEDURE. Perry Watts IMS Health

A SAS Macro Utility to Modify and Validate RTF Outputs for Regional Analyses Jagan Mohan Achi, PPD, Austin, TX Joshua N. Winters, PPD, Rochester, NY

Sudoku Programming with C

A SAS Macro to Generate Caterpillar Plots. Guochen Song, i3 Statprobe, Cary, NC

USING PROC GMAP AND DRILL-DOWN GRAPHICS FOR DATA QUALITY ASSURANCE Meghan Arbogast, Computer Sciences Corporation, Corvallis, OR

Paper ###-YYYY. SAS Enterprise Guide: A Revolutionary Tool! Jennifer First, Systems Seminar Consultants, Madison, WI

Presentation Quality Graphics with SAS/GRAPH

The Missing Semicolon

Merge Processing and Alternate Table Lookup Techniques Prepared by

The GANNO Procedure. Overview CHAPTER 12

1 SAT-DANCE-HEULE INTRO 1

Using Dynamic Data Exchange

An Introduction to PROC SQL. David Beam Systems Seminar Consultants, Inc. - Madison, WI

Sudoku s resolution Using SAS Arrays

Customized Flowcharts Using SAS Annotation Abhinav Srivastva, PaxVax Inc., Redwood City, CA

Contents of SAS Programming Techniques

SAS CURRICULUM. BASE SAS Introduction

THE IMPACT OF DATA VISUALIZATION IN A STUDY OF CHRONIC DISEASE

PASS4TEST. IT Certification Guaranteed, The Easy Way! We offer free update service for one year

A Macro To Generate a Study Report Hany Aboutaleb, Biogen Idec, Cambridge, MA

Using PROC REPORT to Cross-Tabulate Multiple Response Items Patrick Thornton, SRI International, Menlo Park, CA

N N Sudoku Solver. Sequential and Parallel Computing

The Missing Semicolon

Coders' Corner. Scaling Mount GCHART: Using a MACRO to Dynamically Reset the Scale Nina L. Werner, Dean Health Plan, Inc., Madison, WI.

Let's Play a Game: A SAS Program for Creating a Word Search Matrix Robert S. Matthews, University of Alabama at Birmingham, Birmingham, AL

Let s Get FREQy with our Statistics: Data-Driven Approach to Determining Appropriate Test Statistic

An Introduction to SAS Macros Steven First, Systems Seminar Consultants, Madison, WI

Multiple Forest Plots and the SAS System

Common Sense Validation Using SAS

USING SAS SOFTWARE TO COMPARE STRINGS OF VOLSERS IN A JCL JOB AND A TSO CLIST

How to annotate graphics

Data Strategies for Efficiency and Growth

Artificial Intelligence Constraint Satisfaction Problems

DSCI 325: Handout 10 Summarizing Numerical and Categorical Data in SAS Spring 2017

Anticipating User Issues with Macros

Prove QC Quality Create SAS Datasets from RTF Files Honghua Chen, OCKHAM, Cary, NC


Coders' Corner. Paper ABSTRACT GLOBAL STATEMENTS INTRODUCTION

ODS DOCUMENT, a practical example. Ruurd Bennink, OCS Consulting B.V., s-hertogenbosch, the Netherlands

SAS Data Integration Studio Take Control with Conditional & Looping Transformations

Multiple Graphical and Tabular Reports on One Page, Multiple Ways to Do It Niraj J Pandya, CT, USA

SAS seminar. The little SAS book Chapters 3 & 4. April 15, Åsa Klint. By LD Delwiche and SJ Slaughter. 3.1 Creating and Redefining variables

Using SAS Graphics Capabilities to Display Air Quality Data Debbie Miller, National Park Service, Denver, CO

2D Syntax. Version October 30, 2017

SAS CLINICAL SYLLABUS. DURATION: - 60 Hours

INTRODUCTION TO SAS HOW SAS WORKS READING RAW DATA INTO SAS

... WHERE. AnnotaI8 Data.S... XSYS & YSYS. Harie Annotate: How Not to Lose Your Head When Enhancing BAS/GRAPH output

Innovative Performance Improvements Through Automated Flowcharts In SAS

Print the Proc Report and Have It on My Desktop in the Morning! James T. Kardasis, J.T.K. & Associates, Skokie, IL

Tweaking your tables: Suppressing superfluous subtotals in PROC TABULATE

CP2 Revision. theme: dynamic datatypes & data structures

Introduction. Inserting and Modifying Tables. Word 2010 Working with Tables. To Insert a Blank Table: Page 1

The GSLIDE Procedure. Overview. About Text Slides CHAPTER 27

Posters 417. NESUG '92 Proceedings. usinq Annotate Data sets to Enhance Contour Graphics output. Shi Tao Yeh, Environmental Resources Kanaqement, ~nc.

Paper SAS Programming Conventions Lois Levin, Independent Consultant, Bethesda, Maryland

SAS Institute Exam A SAS Advanced Programming Version: 6.0 [ Total Questions: 184 ]

Making Presentations More Fun with DATA Step Graphics Interface (DSGI) Hui-Ping Chen, Eli Lilly and Company, Indianapolis, Indiana

We Have Computers, We Should Use Them!

AURA ACADEMY SAS TRAINING. Opposite Hanuman Temple, Srinivasa Nagar East, Ameerpet,Hyderabad Page 1

SAS Programming Conventions Lois Levin, Independent Consultant

Streamline Table Lookup by Embedding HASH in FCMP Qing Liu, Eli Lilly & Company, Shanghai, China

Transcription:

SAS and Sudoku Presented by: Steve First 2997 Yarmouth Greenway Drive, Madison, WI 53711 Phone: (608) 278-9964 Web: www.sys-seminar.com Systems Seminar Consultants, Inc 1

WISUG? Systems Seminar Consultants, Inc 2

What is Sudoku? Latin Square problem, plus quadrants Subset of set theory, exact cover problem Simple to get started Many levels of difficulty Wildly popular Very addictive. Systems Seminar Consultants, Inc 3

Sudoku Rules Each row, column, quadrant must use digits 1-9 one time. Systems Seminar Consultants, Inc 4

Sudoku Strategies Algorithms Guess or trial and error Systems Seminar Consultants, Inc 5

Why SAS? I know SAS Interesting array capabilities Limited list processing facilities. Systems Seminar Consultants, Inc 6

Why write a Sudoku program? Interesting challenge Donald Knuths Algorithm X using dancing Links Systems Seminar Consultants, Inc 7

My Program Uses arrays to solve Uses naked single and hidden single algorithms Can add new algorithms in future Will solve simple puzzles Will not solve many difficult puzzles. Systems Seminar Consultants, Inc 8

A Systems Breakdown Systems Seminar Consultants, Inc 9

My sudoku Program /* sudoku program that implements naked and hidden single algorithm */ %let graphics=y; /* graphics available? */ /* include annotate macros */ %inc 'C:\Program Files\SAS\SAS 9.1\core\sasmacro\annomac.sas'; goptions hpos=60 vpos=36 target=winprtc; /* graphics options */ options mprint; options nodate nonumber ls=132;title; /* system options */ data sudoko /* create two datasets */ annods(keep=pagenochar STYLE FUNCTION COLOR XSYS YSYS HSYS WHEN POSITION X Y size linetype LINE text) ; *infile 'C:\Documents and Settings\sfirst\Desktop\sudoku\oct15_lvl2.dat'; infile 'C:\Documents and Settings\sfirst\Desktop\sudoku\sep7_lvl4.dat'; /* define 81 variables that initial contain 9 digits each */ length r1c1 r1c2 r1c3 r1c4 r1c5 r1c6 r1c7 r1c8 r1c9 $9; length r2c1 r2c2 r2c3 r2c4 r2c5 r2c6 r2c7 r2c8 r2c9 $9; length r3c1 r3c2 r3c3 r3c4 r3c5 r3c6 r3c7 r3c8 r3c9 $9; length r4c1 r4c2 r4c3 r4c4 r4c5 r4c6 r4c7 r4c8 r4c9 $9; length r5c1 r5c2 r5c3 r5c4 r5c5 r5c6 r5c7 r5c8 r5c9 $9; length r6c1 r6c2 r6c3 r6c4 r6c5 r6c6 r6c7 r6c8 r6c9 $9; length r7c1 r7c2 r7c3 r7c4 r7c5 r7c6 r7c7 r7c8 r7c9 $9; length r8c1 r8c2 r8c3 r8c4 r8c5 r8c6 r8c7 r8c8 r8c9 $9; length r9c1 r9c2 r9c3 r9c4 r9c5 r9c6 r9c7 r9c8 r9c9 $9; Array all81{9,9} $ r1c1--r9c9; /* redefine all 81 vars into an array */ Systems Seminar Consultants, Inc 10

My sudoku Program Array rowa {9,9} $ r1c1--r1c9 /* redefine all 81 vars into row array */ r2c1--r2c9 r3c1--r3c9 r4c1--r4c9 r5c1--r5c9 r6c1--r6c9 r7c1--r7c9 r8c1--r8c9 r9c1--r9c9; /* redefine all 81 vars into column array */ Array cola{9,9} $ r1c1 r2c1 r3c1 r4c1 r5c1 r6c1 r7c1 r8c1 r9c1 r1c2 r2c2 r3c2 r4c2 r5c2 r6c2 r7c2 r8c2 r9c2 r1c3 r2c3 r3c3 r4c3 r5c3 r6c3 r7c3 r8c3 r9c3 r1c4 r2c4 r3c4 r4c4 r5c4 r6c4 r7c4 r8c4 r9c4 r1c5 r2c5 r3c5 r4c5 r5c5 r6c5 r7c5 r8c5 r9c5 r1c6 r2c6 r3c6 r4c6 r5c6 r6c6 r7c6 r8c6 r9c6 r1c7 r2c7 r3c7 r4c7 r5c7 r6c7 r7c7 r8c7 r9c7 r1c8 r2c8 r3c8 r4c8 r5c8 r6c8 r7c8 r8c8 r9c8 r1c9 r2c9 r3c9 r4c9 r5c9 r6c9 r7c9 r8c9 r9c9; /* redefine all 81 vars into quad array */ Array quada{9,9}$ r1c1 r1c2 r1c3 r2c1 r2c2 r2c3 r3c1 r3c2 r3c3 r1c4 r1c5 r1c6 r2c4 r2c5 r2c6 r3c4 r3c5 r3c6 r1c7 r1c8 r1c9 r2c7 r2c8 r2c9 r3c7 r3c8 r3c9 r4c1 r4c2 r4c3 r5c1 r5c2 r5c3 r6c1 r6c2 r6c3 r4c4 r4c5 r4c6 r5c4 r5c5 r5c6 r6c4 r6c5 r6c6 r4c7 r4c8 r4c9 r5c7 r5c8 r5c9 r6c7 r6c8 r6c9 r7c1 r7c2 r7c3 r8c1 r8c2 r8c3 r9c1 r9c2 r9c3 r7c4 r7c5 r7c6 r8c4 r8c5 r8c6 r9c4 r9c5 r9c6 r7c7 r7c8 r7c9 r8c7 r8c8 r8c9 r9c7 r9c8 r9c9; Systems Seminar Consultants, Inc 11

My sudoku Program length work81 $ 81 ; /* 81 byte work area to contain one structure */ array cnta{9} cnt_1-cnt_9; /* array to count digit occurences */ /* mainline portion */ link load_initial; /* load initial puzzle */ change='y'; /* set change flag */ do until(change='n' ); /* keep going until no more changes*/ change='n'; /* change flag to no */ i+1; /* times looped thru */ do Structure='R','C','Q'; /* do rows, cols, then quads */ do struct_no = 1 to 9; /* do all 9 rows, cols, quads */ Link loadwork81; /* move structure to work area */ link naked_singles; /* look for naked singles */ link hidden_singles; /* then look for hidden singles */ link unloadwork81; /* move work area back to arrays */ end; /* end of inner loop */ /* title with interation, struct */ rtitle= 'Interation '!! put(i,3.)!! ' '!! structure!! ' Structure Report'; link report; /* print results so far */ end; /* next structure */ end; /* next loop if still changed */ return; /* end of mainline */ Systems Seminar Consultants, Inc 12

My sudoku Program load_initial: /* read in puzzle, init blnk cells */ do row=1 to 9; /* read 9 rows */ do col=1 to 9; /* and 9 columns */ input all81{row,col} $char1. @; /* input array element from file */ if all81{row,col} in('.',' ') then/* if missing or blank? */ all81{row,col}='123456789'; /* initialize to all 9 possibles */ end; /* end of col loop */ input; /* clear input pointer */ end; /* next row */ rtitle='step1 - initial load '; /* set title */ link report; /* print initial puzzle */ return; /* end of load */ Loadwork81: /* load work with cells from r,c,q */ do cell=1 to 9; /* 9 cells, each 9 digits long */ fposition=((cell-1)*9)+1; /* cell 1 to pos 1, 2 to 10 etc */ if structure="q" then /* if quad? */ cell_in=quada(struct_no,cell); /* move cell from quad array */ else if structure="r" then /* same for rows */ cell_in=rowa(struct_no,cell); else if structure="c" then /* and cols */ cell_in=cola(struct_no,cell); substr(work81,fposition,9)=cell_in;/* move cell in to work area */ end; /* next cell */ save_work81=work81; /* save work to look for changes */ return; /* end of load work */ Systems Seminar Consultants, Inc 13

My sudoku Program /********************************************************************/ /* if cell contains a single candidate, then eliminate candidate */ /* from all cells in structure. */ /********************************************************************/ naked_singles: do cell=1 to 9; fposition=((cell-1)*9)+1; search=left(substr(work81,fposition,9)); if length(search)=1 then /* single dig? */ do; work81=translate(work81,' ',search); /* change all cells inc itself */ substr(work81,fposition,9)=search; /* set single digt back to search*/ end; end; return; /********************************************************************/ /* a digit occurs only once in a structure, but may have other digs */ /* with it. when found, set cell and eliminate in rest of structure*/ /********************************************************************/ hidden_singles: do digit=1 to 9; digit_char=put(digit,1.); cnta{digit}=count(work81,digit_char); if cnta{digit}= 1 then do; fposition=index(work81,digit_char); fposition=(int((fposition-1)/9)*9)+1; end; end; return; substr(work81,fposition,9)=digit_char!!' Systems Seminar Consultants, Inc 14 ';

My sudoku Program unloadwork81: /* reload structure with changed values */ do cell=1 to 9; fposition=((cell-1)*9)+1; if structure="q" then quada{struct_no,cell}=substr(work81,fposition,9); else if structure="r" then rowa{struct_no,cell}=substr(work81,fposition,9); else if structure="c" then cola{struct_no,cell}=substr(work81,fposition,9); end; if work81 ne save_work81 /* was any change made? */ then change='y'; /* yes, set flag */ return; report: /* graphic report */ if "&graphics" ne "y" then goto report_text; pageno+1; pagenochar='page_'!! put(pageno,z2.); %DCLANNO ; x=3; /* title */ y=32; text=rtitle; style='swissb'; size=1.5; position='6'; output; Systems Seminar Consultants, Inc 15

My sudoku Program DO Y=1 TO 28 by 3; if mod(y-1,9)= 0 then size=10; else if mod(y-1,3)= 0 then size=3; else size=1; if size=3 then linetype=2; else linetype=1; %LINE(1,Y,28,Y,BLACK,linetype,size); END; DO X=1 TO 28 by 3; if mod(x-1,9)= 0 then size=10; else if mod(x-1,3)= 0 then size=3; else size=1; if size=3 then linetype=2; else linetype=1; %LINE(X,1,X,28,BLACK,linetype,size); END; Do row=1 to 9; do col=1 to 9; x=3*col -.5; /* trans to lower left origin on 27*27 grid */ y=-3*row + 29.5; savex=x; savey=y; function='label'; Color='Black'; Systems Seminar Consultants, Inc 16

My sudoku Program style='swissb'; position='+'; search=left(all81{row,col}); if length(search)=1 then /* single dig? */ do; text=substr(search,1,1); size=2; output; end; else do fposition=1 to length(search); text=substr(search,fposition,1); size=.8; style='swiss'; color='red'; x=savex; y=savey; if text in ('1','2','3') then y=y+1; if text in ('7','8','9') then y=y-1; if text in ('1','4','7') then x=x-1; if text in ('3','6','9') then x=x+1; output; end; end; end; Systems Seminar Consultants, Inc 17

My sudoku Program report_text: /* text report */ file print; put _page_@; put rtitle; put @1 110*'*'; do row=1 to 9; do col=1 to 9; if col in(1,4,7) then put '*'@; else put ' '@; put +1 all81{row,col} $char9. +1 @; end; put @110 '*'; if row in (3,6,9) then put @1 110*'*'; else do; put 3*'* --------- --------- --------- ' @; put @110 '*'; end; end; put ///; return; run; PROC GREPLAY NOFS IGOUT=WORK.GSEG; DELETE _ALL_; QUIT; PROC Ganno ANNOTATE=annods name=pagenochar;title;run; Systems Seminar Consultants, Inc 18

A Puzzle That Program Can Solve A level 2 Sudoku...5.9.8.6 42....3.6...5.7.9.....97521.....8.7. 6...4.5....29 8.7.2.6.. Systems Seminar Consultants, Inc 19

Program Output Systems Seminar Consultants, Inc 20

Program Output Systems Seminar Consultants, Inc 21

Program Output Systems Seminar Consultants, Inc 22

Program Output Systems Seminar Consultants, Inc 23

Program Output Systems Seminar Consultants, Inc 24

Program Output Systems Seminar Consultants, Inc 25

Program Output Systems Seminar Consultants, Inc 26

Program Output Systems Seminar Consultants, Inc 27

Program Output (Note Naked Pair) Systems Seminar Consultants, Inc 28

Program Output Systems Seminar Consultants, Inc 29

Puzzle Solved Systems Seminar Consultants, Inc 30

A Possible Use for SAS? Systems Seminar Consultants, Inc 31

Other Algorithms Naked pairs, triples, quads Hidden pairs, triples, quads X-wing Swordfish, jellyfish Color trap, wrap, wing Empty rectangle, hinge Remote pair Systems Seminar Consultants, Inc 32

Algorithm X and Dancing Links A trial and error solver by Donald Knuth. If x points to doubly linked list, L[x], R[x] point to predecessor, successor. Then L[R[x]] L[x], R[L[x]] R[x] removes x. And L[R[x]] x, R[L[x]] x Puts x back In the list. Systems Seminar Consultants, Inc 33

Resources Wikipedia Suducue.net Many, others Systems Seminar Consultants, Inc 34

But Seriously Folks Systems Seminar Consultants, Inc 35

Contact Us SAS Training, Consulting, & Help Desk Services 2997 Yarmouth Greenway Drive Madison, WI 53711 (608) 278-9964 Fax (608) 278-0065 www.sys-seminar.com Steve First, President 608-278-9964 x 306 sfirst@sys-seminar.com Systems Seminar Consultants, Inc 36