SAS Enterprise Guide: Pick a Winner Randomly

sas stored process book winners

To pick the winners of the 50 Keys to Learning SAS Stored Processes book, my first thought was to print the list and then put everyone’s name in a hat. Angela brilliantly suggested that we use one of the SAS Random functions.  However, since there was a list  of names I really needed a random number between two values.  This brought to mind the MS Excel RANDBETWEEN function – but how do you translate that function to SAS Enterprise Guide code?

Getting a Random Number between Two Values

I have to admit for a one-off process like picking a random number,  MS Excel would be my goto tool. MS Excel has a function called RANDBETWEEN() that allows you to provide two numbers and it then selects a random value between those two numbers.  I tried to use the SAS RANDOM functions – but I couldn’t figure out how to make it work in 5 minutes (my personal patience meter) so I needed an expert. 

Consult with a SAS Expert

sas stored process book winners

Lucky for me SAS-L had the answer – it’s one of the places I search for SAS tips when I’m stuck.  In August 2000, Mark Terjeson wrote a post called “Just for Fun: Excel-SAS Corollary Functions/Formula” describing how to translate some common Excel functions into SAS.  This is where I found the magic. In the following figure, you can see the code I used to select the two winning numbers.  After getting my two numbers, I matched the line number to the spreadsheet line number to get Michelle Homes and Wex Lee.  Congratulations you have won a copy of the 50 Keys to Learning SAS Stored Processes!

No Worries if You are not the Winner!

You can purchase your copy of The 50 Keys to Learning SAS Stored Processes from this site or from Amazon!  We can’t wait to hear your reviews!

 

Never miss a BI Notes post!

Click here for free subscription. Once you subscribe you'll be asked to confirm your subscription through your email account. You email address is kept private and you can unsubscribe anytime.

11 thoughts on “SAS Enterprise Guide: Pick a Winner Randomly

  1. This is great! I’d love to read this book and put the great tips there into use.

Comments are closed.