*
;
/*
From: darkiet@usa.pipeline.com(J T)
Newsgroups: comp.soft-sys.sas
Subject: Re: Generating Permutations
Date: 20 Jan 1996 18:05:54 GMT
Organization: Pipeline USA

You can try this little piece.  If you change this macro to use array, you
might be able to break the 9-character limitation. The idea is to add onto
the same varable in the same dataset to get combinations and permutations.
Good luck.
*/
***********************************************;
* Produce all permutations                         ;
* Only work for STRING up to 9 characters long ;
***********************************************;

%macro permu(string,n,p);
data perm(keep=last);
  do last=1 to &n;
    output;
  end;
run;
%let q=%eval(&p-1);
%do i=1 %to &q;
data perm(keep=current rename=(current=last));
  set perm;
  do i=1 to &n;
    if index(trim(left(last)),trim(left(i)))=0 then do;
        current=last*10+i;
        output;
    end;
  end;
run;
%end;
proc sort data=perm nodup;
  by last;
run;
data perm(keep=current);
  set perm;
  length current $ &p;
  current=translate(trim(left(last)),"&string",'123456789');
run;
%mend;

%permu(ABCD,4,3);

proc print;
run;

*
;