| Date: | Wed, 14 Jan 2009 09:16:33 -0800 |
| Reply-To: | shiling99@YAHOO.COM |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | Shiling Zhang <shiling99@YAHOO.COM> |
| Organization: | http://groups.google.com |
| Subject: | Re: Cartesian Product by Group |
|
| Content-Type: | text/plain; charset=UTF-8 |
If the variable names are different, then one can use the data set
rename option.
For example, q1(rename=(q1=q))
set q1(in=a rename=(q1=q) ) q2(in=b rename=(q2=q)) q3(in=c rename=
(q3=q));
will do the trick.
HTH
dc353@hotmail.com wrote:
> On Jan 13, 11:42�am, shilin...@yahoo.com wrote:
> > It is not a �Cartesian product but a set of all data sets.
> >
> > Here is an example.
> > HTH
> >
> > data all;
> > � set q1(in=a ) q2(in=b) q3(in=c);
> > � group=(a=1)*1 + (b=1)*2 + (c=1)*3;
> > run;
> >
> > On Jan 13, 9:57�am, "dc...@hotmail.com" <dc...@hotmail.com> wrote:
> >
> >
> >
> > > I have the following data:
> >
> > > � q1
> > > � 5
> > > � 8
> > > � 4
> >
> > > � q2
> > > � 1
> > > 10
> >
> > > � q3
> > > � 1
> > > � 2
> > > � 3
> >
> > > ...
> >
> > > each data set represents a question and each row represents an answer
> > > to that question. �I have N questions each with M(n) answers. �I
> > > wondering how to create a Cartesian product between all N questions.
> > > In the case where N = 3 from the above data the answer would like:
> >
> > > 5 1 1
> > > 5 1 2
> > > 5 1 3
> > > 5 10 1
> > > 5 10 2
> > > 5 10 3
> > > 8 1 1
> > > 8 1 2
> > > 8 1 3
> > > 8 10 1
> > > 8 10 2
> > > 8 10 3
> > > 4 1 1
> > > 4 1 2
> > > 4 1 3
> > > 4 10 1
> > > 4 10 2
> > > 4 10 3
> >
> > > I was wondering if I create the dataset as:
> > > group � answer
> > > 1 � � � � � � 5
> > > 1 � � � � � � 8
> > > 1 � � � � � � 4
> > > 2 � � � � � � 1
> > > 2 � � � � � � 10
> > > 3 � � � � � � 1
> > > 3 � � � � � � 2
> > > 3 � � � � � � 3
> >
> > > Is there a way to do a Cartesian product by group?- Hide quoted text -
> >
> > - Show quoted text -
>
> Hi,
>
> Your code produces the following output for ALL:
>
> Q1 Q2 Q3 group
> 1 5 . . 1
> 2 8 . . 1
> 3 4 . . 1
> 4 . 1 . 2
> 5 . 10 . 2
> 6 . . 1 3
> 7 . . 2 3
> 8 . . 3 3
>
> However the following code produces the correct output:
>
> proc sql;
> create table ALL as
> select *
> from q1,q2,q3;
> quit;
>
> I believe this is the basic form for a cartesian product. My question
> has to do with creating the input dataset as 1 set as opposed to 1
> dataset for each group and creating the cartesian product without
> having to know how many groups are in the combined dataset.
|