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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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