BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ballardw
Super User

Here are two pieces for looking at a reduced problem similar to the lottery.

 

/* here is a quick way to simulate the possible universe considering
   order using balls with 1 to 6*/
data allposs;
   do ball1= 1 to 6;
      do ball2 = 1 to 6;
         if ball1 ne ball2 then output;
      end;
   end;
run;
/* for your other summary data exercise would be change these
results to the ordered sequence */

/* you will note immediately that this is 2 6-sided dice with
   the doubles removed
*/
/* simulating outcomes from above with a lottery*/
data sim;
   p1= 1/6;  /*probability of each number theoretically is 1/6 if fair for first ball draw*/
   array p2 {6} ; /* to hold probabilities for the second draw. Arrays are a short cut way
                  of referencing many values using and indexing value to tell which
                 one if interest at the time. This statement creates variable
                 p21 p22 p23 p24 p25 p26
                 */
   /* the 5 below says to conduct 5 trials, increase as interested*/
   do trial=1 to 5;
      /* select first draw*/
      ball1 = rand('TABLE',p1,p1,p1,p1,p1,p1);
      /* set the probability of drawing any ball except
         that already picked, since we know only one ball is picked
         we know the prob. Could exend to 1/(n - number of balls already selected
      */
      do i= 1 to dim(p2);
         if i ne ball1 then p2[i]=1/5;
         else p2[i]=0;
      end;
      /* select the second ball*/
      ball2 = rand('TABLE',of p2(*));
      output;
   end;
   /* remove the unwanted counter and the probability values*/
   drop i p:;
run;


That second data step could be extended with a bit more loop nesting and holding which ball to select in an array. The probability array, to use this way, would need to have one position for each possible ball so the array p2 {6} would change to {69} for current powerball.

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 15 replies
  • 3569 views
  • 3 likes
  • 3 in conversation