how to create the permutation of k items out of total n items.I don't have IML.
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.
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.")
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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!