A “LOTTO” SAS for you! or, “Check Your Balls with SAS Arrays” By Keith McWhorter Georgia Technology Authority January 30, 2007.

Slides:



Advertisements
Similar presentations
The INFILE Statement Reading files into SAS from an outside source: A Very Useful Tool!
Advertisements

SAS Programming:File Merging and Manipulation. Reading External Files (review) data barf; * create the dataset BARF; infile ’s:\mysas\Table7.1'; * open.
Slide C.1 SAS MathematicalMarketing Appendix C: SAS Software Uses of SAS  CRM  datamining  data warehousing  linear programming  forecasting  econometrics.
Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.
Creating a Compact Columnar Output with PROC REPORT Walter R. Young Principal Clinical Programmer Analyst Wyeth.
MASUG December 5, Agenda Announcements Announcements Tips & Tricks Tips & Tricks Presentation: Presentation: Working Smarter, Not Harder with DDE:
SAS Output Delivery System. Find heart in the sashelp library Double click.
Beginning Data Manipulation HRP Topic 4 Oct 19 th 2011.
Trials and Tribulations of creating DDI Codebooks at the University of Guelph A.Michelle Edwards and Carol Perry, Data Resource Centre, University of Guelph.
Guide To UNIX Using Linux Third Edition
Basic And Advanced SAS Programming
DePaul Bears Try Your Luck!. Why buy this product? Approximately 1,000,000 cell phone users Approximately 2,000,000 or more people play the lottery New.
PROC_CODEBOOK: An Automated, General Purpose Codebook Generator
Understanding SAS Data Step Processing Alan C. Elliott stattutorials.com.
Data Cleaning 101 Ron Cody, Ed.D Robert Wood Johnson Medical School Piscataway, NJ.
Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities.
Week 3 Topic - Descriptive Procedures Program 3 in course notes Cody & Smith (Chapter 2)
“SAS macros are just text substitution!” “ARRRRGGHHH!!!”
I OWA S TATE U NIVERSITY Department of Animal Science Writing Flexible Codes with the SAS Macro Facility (Chapter in the 7 Little SAS Book) Animal Science.
Copyright © 2010, Meta-Xceed, Inc. All rights reserved. BI Flash and all other Meta-Xceed Inc. product or service names are registered trademarks or trademarks.
Lecture 5 Sorting, Printing, and Summarizing Your Data.
Chapter 21 Reading Hierarchical Files Reading Hierarchical Raw Data Files.
RTSUG 04Feb2014: Beyond Directory Listings in SAS By: Jim Worley.
Recursion. What is recursion? Solving a problem in terms of itself or repeating objects in a “self-similar” way A recursive function is a function that.
Lesson 5 - Topics Formatting Output Working with Dates Reading: LSB:3:8-9; 4:1,5-7; 5:1-4.
SAS Macro: Some Tips for Debugging Stat St. Paul’s Hospital April 2, 2007.
SAS Efficiency Techniques and Methods By Kelley Weston Sr. Statistical Programmer Quintiles.
EPIB 698C Lecture 2 Notes Instructor: Raul Cruz 2/14/11 1.
I OWA S TATE U NIVERSITY Department of Animal Science Getting Your Data Into SAS (Chapter 2 in the Little SAS Book) Animal Science 500 Lecture No. 3 September.
01/20151 EPI 5344: Survival Analysis in Epidemiology SAS code and output February 24, 2015 Dr. N. Birkett, School of Epidemiology, Public Health & Preventive.
Macro Overview Mihaela Simion. Macro Facility Overview Definition : The SAS Macro Facility is a tool within base SAS software that contains the essential.
SAS Software Version 8 The Output Delivery System.
1 Efficient SAS Coding with Proc SQL When Proc SQL is Easier than Traditional SAS Approaches Mike Atkinson, May 4, 2005.
1 Filling in the blanks with PROC FREQ Bill Klein Ryerson University.
MIPS coding. slt, slti slt $t3, $t1, $t2 – set $t3 to be 1 if $t1 < $t2 ; else clear $t3 to be 0. – “Set Less Than.” slti $t3, $t1, 100 – set $t3 to be.
Define your Own SAS® Command Line Commands Duong Tran – Independent Contractor, London, UK Define your Own SAS® Command Line Commands Duong Tran – Independent.
Publishing to PDF SNUG Quarter 2. Overview n What is PDF? n Why use PDF? n Creating PDF files with SAS Software n Issues n Advanced PDF files with SAS.
SAS ODS (Output Delivery System) Donald Miller 812 Oswald Tower ;
1 Data Manipulation (with SQL) HRP223 – 2010 October 13, 2010 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This.
Lesson 6 - Topics Reading SAS datasets Subsetting SAS datasets Merging SAS datasets.
FOR MONDAY: Be prepared to hand in a one-page summary of the data you are going to use for your project and your questions to be addressed in the project.
Computing with SAS Software A SAS program consists of SAS statements. 1. The DATA step consists of SAS statements that define your data and create a SAS.
FORMAT statements can be used to change the look of your output –if FORMAT is in the DATA step, then the formats are permanent and stored with the dataset.
BMTRY 789 Lecture 6: Proc Sort, Random Number Generators, and Do Loops Readings – Chapters 5 & 6 Lab Problem - Brain Teaser Homework Due – HW 2 Homework.
Lesson 2 Topic - Reading in data Programs 1 and 2 in course notes –Chapter 2 (Little SAS Book)
Learning Javascript From Mr Saem
Thinking about Graphs The Grammar of Graphics and SAS.
Basic HTML Page 1. First Open Windows Notepad to type your HTML code 2.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 14 & 19 By Tasha Chapman, Oregon Health Authority.
Build your Metadata with PROC CONTENTS and ODS OUTPUT Louise S. Hadden Abt Associates Inc.
Better Metadata Through SAS® II: %SYSFUNC, PROC DATASETS, and Dictionary Tables.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 5 & 6 By Ravi Mandal.
Beautiful PROC CONTENTS Output Using the ODS Excel Destination Suzanne Dorinski SESUG 2015 Disclaimer: Any views expressed are those of the author and.
SAS Essentials How SAS Thinks
More Loops.
Beautiful PROC CONTENTS Output Using the ODS Excel Destination
Automating SAS through the Power of VB Script
Purpose Real life scenario: I have a set of reports to refresh every month but data is only available at any day during Day 3 – 5 at beginning of each.
Directions slide: 1. Complete the title slide.
or, “Check Your Balls with SAS Arrays”
Directions slide: 1. Complete the title slide.
Type your presentation title here
Title Introduction: Discussion & Conclusion: Methods & Results:
Tips and Tricks for Using Macros to Automate SAS Reporting.
Directions slide: 1. Complete the title slide.
Hans Baumgartner Penn State University
Speaker name Title Title
Speaker name Title Title
Presentation transcript:

A “LOTTO” SAS for you! or, “Check Your Balls with SAS Arrays” By Keith McWhorter Georgia Technology Authority January 30, 2007

A Mega-Group Effort When Mega-Millions’ Jackpot > $50Mil People in the office put in $1 - $5 each Usually get 75 to 100 tickets Could take a while to check them all!

Ways to Win 5 numbers plus Mega Ball Match only Mega Ball wins small amount Match 1 or more of the first 5 + Mega If Mega doesn’t match – must have at least 3 of the 5 others.

Let SAS Check ‘em! Input file: 01/09/  Draw Date & winning #s …

The Code DATA results(KEEP=ldate w1 w2 w3 w4 w5 w6) ournums(KEEP=d1 d2 d3 d4 d5 d6 flg1 flg2 flg3 flg4 flg5 flg6); INFILE 'SGSS.KEITH.GA010907'; ARRAY WIN[6]2 WIN1-WIN6; *WINNING NUMBERS; ARRAY FLG[6] $ 2FLG1-FLG6; * Match Flags = Y or N; RETAIN WIN1-WIN6;* KEEP WINNING NUMS IN MEMORY ;

First Time Through… IF _N_=1 THEN DO; INPUT ldate MMDDYY10. W1 W2 W3 W4 W5 W6 ; WIN[1] = W1; WIN[2] = W2; WIN[3] = W3; WIN[4] = W4; WIN[5] = W5; WIN[6] = W6; OUTPUT results; END;

Read a set of our numbers & check ELSE DO; INPUT D1 D2 D3 D4 D5 D6; ARRAY OUR[6] 2 D1 D2 D3 D4 D5 D6; * OUR NUMBERS; FLG[6]='N'; IF OUR[6] = WIN[6] THEN FLG[6]='Y';*Mega?; DO I = 1 TO 5; *Loop through other 5; IFOUR[I]=WIN[1] OROUR[I]=WIN[2] OROUR[I]=WIN[3] OROUR[I]=WIN[4] OROUR[I]=WIN[5] THEN FLG[I]='Y'; *Set flag if match; ELSE FLG[I]='N'; END; OUTPUT ournums; *Write it out!; END;

Add Var “x” with # matches DATA wincnt; SET ournums; x=0; IF FLG1 = 'Y' then x+1; IF FLG2 = 'Y' then x+1; IF FLG3 = 'Y' then x+1; IF FLG4 = 'Y' then x+1; IF FLG5 = 'Y' then x+1; run;

Determine Level of Win DATA winlvl; SET wincnt; IF FLG6 = 'Y' then do; * if megaball matches... ; SELECT; WHEN (X = 5)L=1; WHEN (X = 4)L=2; WHEN (X = 3)L=3; WHEN (X = 2)L=4; WHEN (X = 1)L=5; WHEN (X = 0)L=6; END;* end select ; END;* end if ;

Determine level of win… ELSE DO; * megaball does not match ; SELECT; WHEN (X = 5)L=7; WHEN (X = 4)L=8; WHEN (X = 3)L=9; OTHERWISE DELETE; END; * end select; END; * end else; run;

Format the Levels PROC FORMAT; VALUE lvl 1= ' JACKPOT!!' 2= ' 4 + MB' 3= ' 3 + MB' 4= ' 2 + MB' 5= ' 1 + MB' 6= ' 0 + MB' 7= ' 5 of 5' 8= ' 4 of 5' 9= ' 3 of 5' ; RUN;

the Results! FILENAME MY_FILE ) SUBJECT="Group A Results" TYPE="TEXT/HTML" ; RUN; ODS listing close; ODS HTML BODY=MY_FILE;

First the Winning Numbers PROC PRINT data=results noobs split='*'; by ldate; format ldate MMDDYY10.; title 'Results for #byval1'; title2 'Winning Numbers'; var w1 w2 w3 w4 w5 w6; label w1 = '* ' w2 = '* ' w3 = '* ' w4 = '* ' w5 = '* ' w6 = '* ' ldate = ' ' ; run;

Now Print Our Matches PROC PRINT data=winlvl noobs split='*'; title 'Our Winning Numbers'; footnote 'Total Winnings = $6!';*Manual ; format L lvl.; var d1 d2 d3 d4 d5 d6 L; label d1 = '* ' d2 = '* ' d3 = '* ' d4 = '* ' d5 = '* ' d6 = '* ' L= '# of*Matches' ; run; ods html close;

The Resulting

Thank you!