Calcite | Level 5

## How to create Combinations and Permutations

how to create the permutation of k items out of total n items.I don't have IML.

3 REPLIES 3
Super User

## Re: How to create Combinations and Permutations

SAS has some CALL routines that handles this.

Here's a blog post covering permutations within a data step, no IML needed.

https://blogs.sas.com/content/iml/2010/10/13/generate-all-permutations-in-sas.html

PS. Please note I've modified your subject line to be more relevant to your question.

@jchang_70 wrote:

how to create the permutation of k items out of total n items.I don't have IML.

Jade | Level 19

## Re: Combinations and Permutations Made Easy in SAS Studio 4.3

Hello @jchang_70 and welcome to the SAS Support Communities!

Check out the combinatorial functions and CALL routines (see section "Combinatorial" in the list of all functions), e.g. ALLCOMB and LEXPERK, if you have access to these. (I'm not quite sure because of potential limitations of SAS Studio to "functions that run on the CAS server.")

SAS Super FREQ

## Re: How to create Combinations and Permutations

Here's a way to do it with the CLP solver in PROC OPTMODEL:

``````proc optmodel;
num n = 5;
num k = 3;
var X {1..k} >= 1 <= n integer;
con Permutation: alldiff(X);
solve with clp / findallsolns;
for {s in 1.._NSOL_} print {j in 1..k} X[j].sol[s];
create data want from [s]=(1.._NSOL_) {j in 1..k} <col('X'||j)=X[j].sol[s]>;
quit;``````
Discussion stats
• 3 replies
• 436 views
• 1 like
• 4 in conversation