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 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

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