Help using Base SAS procedures

Simulate lotto number combinations

Reply
New Contributor
Posts: 3

Simulate lotto number combinations


I am trying to simulate combinations based on 5 coordinates (datset below):

data coord;

input x 1. y 1.;

datalines;

11

32

55

91

14

run;

Every combination must begin with (1,1) and end with (1,1) i.e.

(1,1) -> (3,2)-> (5,5)-> (9,1)-> (1,4)-> (1,1)

and all combinations must be unique and finally that there can't be the above route and

(1,1) ->(1,4)-> (9,1)-> (5,5)-> (3,2)-> (1,1)

as both routes are the same but in opposite directions.

Is there a way to do this in sas?

Super User
Posts: 10,500

Re: Simulate lotto number combinations

What do expect the output data set to look like?

Super User
Posts: 10,500

Re: Simulate lotto number combinations

How many points ( pairs ) are you going to be using.

The following creates a text ordered pair variable and permutes them. Uniqueness I'm not sure quite what your rules may be. Note that if you are using many pairs that the number of records for output goes up as N!.

data coord;
input x 1. y 1. ;
length coord $ 8;
coord=catt(x,',',y);
retain start ;
if _n_= 1 then start= coord;
datalines;
11
32
55
91
14
run;

/* flip the column to a row to get the ordered pairs in one record to permute later*/

proc transpose data=coord out=coordtrans;
by start;
var coord;
run;

/* you could trop some of the variables n, nfact, j. also the COL1 or start will have your first pair

so you also have it available as an end */

data next;
   set coordtrans;
   array c Col2-col5; /* change the 5 to the number of pairs used*/
   n=dim(c);
   nfact=fact(n);
   do j=1 to nfact;
      call lexperm(j,  of c

  • );
          output;
       end;
    run;
  • Super User
    Posts: 9,681

    Re: Simulate lotto number combinations

    It is called all permutations not combinations.

    Want data step code or IML code ?

    Suggest you post it at IML forum, since it is question about simulating data.

    data coord;
    input x 1. y 1.;
    datalines;
    11
    32
    55
    91
    14
    ;
    run;
    proc sql noprint;
     select count(*) into : n
      from coord
       where x ne 1 or y ne 1;
     select quote(cats(x,y)) into : list separated by ' '
      from coord
       where x ne 1 or y ne 1;
    quit;
    
    data _null_;
    array x{&n} $2 (&list);
    n=dim(x);
    nfact=fact(n);
    do i=1 to nfact;
     change=allperm(i, of x{*});
     put i 5. +2 '11' +2 x{*} '11';
    end;
    run;
    
    
    
    
    
    

    Xia Keshan

    Ask a Question
    Discussion stats
    • 3 replies
    • 312 views
    • 0 likes
    • 3 in conversation