SAS Enterprise Guide: Pick a Winner Randomly

This post was kindly contributed by Business Intelligence Notes for SAS® BI Users - go there to comment and to read the full post.

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. 

randbetween function excel SAS Enterprise Guide: Pick a Winner Randomly

Consult with a SAS Expert

winner SAS Enterprise Guide: Pick a Winner Randomly

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!

This post was kindly contributed by Business Intelligence Notes for SAS® BI Users - go there to comment and to read the full post.