BookmarkSubscribeRSS Feed
jchang_70
Calcite | Level 5

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

3 REPLIES 3
Reeza
Super User

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.


 

FreelanceReinh
Jade | Level 19

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.")

RobPratt
SAS Super FREQ

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;

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

Discussion stats
  • 3 replies
  • 921 views
  • 1 like
  • 4 in conversation