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?
What do expect the output data set to look like?
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
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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.