Generate all permutations of elements in SAS
March 30, 2021
1 min
“Permutation”: Permutation can simply be defined as the several ways of arranging few or all members within a specific order. It is the process of legibly arranging from chaos. This is what is termed a Permutation.
To Generate all permutations of elements in SAS, use the [FACT](https://documentation.sas.com/?cdcId=vdmmlcdc&cdcVersion=8.1&docsetId=lefunctionsref&docsetTarget=p17pfkttmfknqvn1wjr33oyz9yu6.htm&locale=en) function then determines the permutation using the CALL ALLPERM.
[CALL ALLPERM](https://documentation.sas.com/?docsetId=lefunctionsref&docsetTarget=p0nqrwr48k3lsyn1rtv28qvr7feh.htm&docsetVersion=3.2&locale=en) and [CATS](https://www.9to5sas.com/character-function-in-sas/) function are new in SAS 9.0.
data ex1;drop i perms x1-x3;array x (3) $3 ('a' 'b' 'c');length perm $3;perms=fact(3);do i=1 to perms;call allperm(i, of x(*));perm=cats(of x(*));output;end;run;```**"Output":****"Combination": **The combination is a process of selecting the objects or items from a set or the collection of objects, such that (unlike permutations) the order of selection of objects does not matter. It refers to the combination of N things taken from a group of K at a time without repetition.```sasdata test(drop=x1-x3 h1-h3);array x $3 ('a' 'b' 'c');array h $3;n=dim(x);do k = 1 to 3;ncomb=comb(n,k);call sortc(of x(*));call missing(of h(*));do j=1 to ncomb;rc=allcomb(j,k,of x);if rc<0 thenleave;do i= 1 to k;h=x;end;allcombns=cats(of h(*));output;end;end;drop i j k n ncomb rc;run;```**"Output":**export const _frontmatter = {"title":"Generate all permutations of elements in SAS","slug":"generate-all-permutations-of-elements-in-sas","date":"2021-03-30T08:58:30","modified":"2021-08-04T09:49:51","excerpt":"To Generate all permutations of elements in SAS, use the FACT function then determine the permutation using the CALL ALLPERM.","author":"Subhro","authorSlug":"subhroster","categories":["SAS PROGRAMS"],"tags":[],"wordpressId":8628,"wordpressLink":"https://www.9to5sas.com/generate-all-permutations-of-elements-in-sas/","featuredImage":8706,"type":"post"}