Date:  Tue, 14 Dec 2010 11:57:17 0500 
ReplyTo:  bbser2009 <bbser2009@GMAIL.COM> 
Sender:  "SAS(r) Discussion" <SASL@LISTSERV.UGA.EDU> 
From:  bbser2009 <bbser2009@GMAIL.COM> 
Subject:  Re: code, find all combinations 

InReplyTo:  <BLU152w22D5AADE267A9A705BA596DE130@phx.gbl> 
ContentType:  text/plain; charset="usascii" 
Toby
Thanks a lot for pointing out this to me.
BTW, it seems like that Data _null_ gave me two pieces of code, any one of
which alone can do the job, right?
Max
From: toby dunn [mailto:tobydunn@hotmail.com]
Sent: December1410 11:45 AM
To: bbser2009@gmail.com; sasl@listserv.uga.edu
Subject: RE: code, find all combinations
The AllComb family of functions and call routines were released in 9.2. So
if your using 9.1.x then you can't access them.
Toby Dunn
"I'm a hell bent 100% Texan til I die"
"Don't touch my Willie, I don't know you that well"
> Date: Tue, 14 Dec 2010 11:40:40 0500
> From: bbser2009@GMAIL.COM
> Subject: Re: code, find all combinations
> To: SASL@LISTSERV.UGA.EDU
>
> Data _null_
>
> When running your code, I got this error info below (but still get the
> desired results). Could you help me fix it? Thanks.
>
> Max
>
>
> data _null_;
> 7 array a[4] (1 2 3 4);
> 8 k = 3;
> 9 n = dim(a);
> 10 do j=1 to comb(n,k);
> 11 call allcomb(j,k,of a[*]);
> 
> 251
> ERROR 251185: The subroutine ALLCOMB is unknown, or cannot be accessed.
> Check your spelling.
> Either it was not found in the path(s) of executable images,
> or there was incorrect or missing subroutine descriptor information.
>
> Original Message
> From: Data _null_; [mailto:iebupdte@gmail.com]
> Sent: December1410 7:30 AM
> To: bbser2009
> Cc: SASL@listserv.uga.edu
> Subject: Re: code, find all combinations
>
> PROC PLAN and ALLCOMB with example like the documentation. RTM...
>
> proc plan ordered;
> factors obs=%sysfunc(comb(4,3)) k=3 of 4 comb;
> run;
> quit;
>
> data _null_;
> array a[4] (1 2 3 4);
> k = 3;
> n = dim(a);
> do j=1 to comb(n,k);
> call allcomb(j,k,of a[*]);
> put j 5. +3 @;
> do i = 1 to k;
> put a[i] 3. @;
> end;
> put;
> end;
> run;
>
> data _null_;
> array x[5] $3 ('ant' 'bee' 'cat' 'dog' 'ewe');
> n=dim(x);
> k=3;
> ncomb=comb(n,k);
> do j=1 to ncomb+1;
> call allcomb(j, k, of x[*]);
> put j 5. +3 x1x3;
> end;
> run;
>
> On Mon, Dec 13, 2010 at 10:33 PM, bbser2009 <bbser2009@gmail.com> wrote:
> > I wrote a specific code finding all samples of size 3 from the
population
> > consisting of 1, 2 ,3, 4.
> > The idea is direct:
> > First get data set like this, no repeated values in each observation.
> > 1 2 3
> > 2 4 3
> > 2 1 3
> > ...
> >
> > Then bubblesort each observation from small to big.
> > 1 2 3
> > 2 3 4
> > 1 2 3
> > ...
> >
> > Next bygroup observations that are identical with each other.
> > 1 2 3
> > 1 2 3
> > ...
> > 2 3 4
> > 2 3 4
> > ...
> >
> > At last, output the last observation of each bygroup to get all the
> > samples.
> > 1 2 3
> > 1 2 4
> > 1 3 4
> > 2 3 4
> > (For code, see bottom)
> >
> > Apparently this algorithm/code is hard to generalize.
> > So I am curious about how people have addressed this issue in a more
> general
> > way?
> > I guessed the general algorithm had to be complicated.
> > By any chance, however, does anyone know at least what key ideas lay
> behind
> > it?
> > Any comments are welcome!
> >
> > Thanks.
> >
> > Max
> >
> > *== Get the all nonrepeated permutations of 1, 2, 3, 4 ==;
> > data permutation(drop=i j k);
> > do i=1 to 4;
> > do j=1 to 4;
> > do k=1 to 4;
> > if (i ne j) and (i ne k) and (j ne k) then
> > do;
> > x1=i;
> > x2=j;
> > x3=k;
> > output;
> > end;
> > end;
> > end;
> > end;
> > run;
> >
> > *== Sorting each observation ==;
> > data obs_sorting(drop=temp i j);
> > set permutation;
> > array x{3};
> > do i=1 to 31;
> > do j=1 to 3i;
> > if x[j+1]<x[j] then
> > do;
> > temp=x[j];
> > x[j]=x[j+1];
> > x[j+1]=temp;
> > end;
> > end;
> > end;
> > run;
> >
> > *== Get all samples of size 3 ==;
> > proc sort data=obs_sorting out=grouping;
> > by x1x3;
> > run;
> >
> > data samples;
> > set grouping;
> > by x1x3;
> > if last.x3;
> > output;
> > run;
> >
> > proc print data=samples;
> > run;
> >
