Date: Tue, 3 Feb 2009 06:54:52 -0800
Reply-To: chumba <vikas.dharamsattu@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: chumba <vikas.dharamsattu@GMAIL.COM>
Organization: http://groups.google.com
Subject: Re: Combining 3 datasets into a file row by row one after the
Content-Type: text/plain; charset=ISO-8859-1
On Feb 3, 6:18 pm, dorjeta...@GOOGLEMAIL.COM (karma) wrote:
> Hi Chumba,
>
> The code posted by data _null_ is quite suited for this, if you had to
> do it inonestep.
>
> Dataone;
> input var;
> cards;
> 123
> 456
> ;
> Data two;
> input var;
> cards;
> 112233
> 445566
> ;
> Data three;
> input var;
> cards;
> 111222333
> 444555666
> ;
> run;
> data weave;
> if _n_=1 then do;
> var = 111;
> output;
> end;
> if not end1 then do;
> setOneend=end1;
> output;
> end;
> if not end2 then do;
> set Two end=end2;
> output;
> end;
> if not end3 then do;
> set Three end=end3;
> output;
> end;
> if sum(of end:) eq3;
> var = 999;
> output;
> stop;
> run;
> proc print;
> run;
>
> Alternatively, as Nat's solution worked for you, you could read it in
> again and create another dataset with your additional information
> added.
>
> Dataone;
> input var;
> cards;
> 123
> 456
> Data two;
> input var;
> cards;
> 112233
> 445566
> Data three;
> input var;
> cards;
> 111222333
> 444555666
> run;
>
> ** add a line counter to each data set;
> Dataone;
> setone;
> line = _n_;
> run;
> Data two;
> set two;
> line = _n_;
> run;
>
> Data three ;
> set three ;
> line = _n_;
> run;
>
> * now interleave the three files using a set and by statement;
>
> Data Final;
> setonetwo three;
> by line;
>
> run;
>
> data finalfinal;
> var = 111; output;
> do until(eof);
> set final end=eof;
> by line;
> output;
> end;
> var=999; output;
> stop;
> run;
> proc print;run;
>
> HTH
>
> 2009/2/3chumba <vikas.dharamsa...@gmail.com>:
>
>
>
> > On Feb3, 4:33 am, dorjeta...@GOOGLEMAIL.COM (karma) wrote:
> >> Hi Peetie,
>
> >> Your solution assumes that either alldatasetshave the same number of
> >> observations, or that table 1 and 2 have at most, 1 record more than
> >> table3. If the end of buffer for any dataset is reached at any
> >> point, the datastep will stop executing. For example num =9 will not
> >> be present on the final dataset.
>
> >> dataone;
> >> input num @@;
> >> cards;
> >> 1 4
> >> ;
> >> data two;
> >> input num @@;
> >> cards;
> >> 2 5
> >> ;
> >> data three;
> >> input num @@;
> >> cards;36 9
> >> ;
> >> data merged;
> >> setone;output;
> >> set two;output;
> >> set three;output;
> >> run;
> >> proc print;run;
>
> >> 2009/2/2 Peetie Wheatstraw <peetie.wheatst...@gmail.com>:
>
> >> > Perhaps the simplest approach:
>
> >> > data all3;
> >> > set table1; output;
> >> > set table2; output;
> >> > set table3; output;
> >> > run;
>
> >> > Peetie
>
> >> > On Mon, 2 Feb 2009 03:00:16 -0800 (PST), chumba <vikas.dharamsa...@gmail.com> wrote:
>
> >> >>Hey All,
>
> >> >>I need to combine3datasetsintoafilerowbyrowsuch that first
> >> >>observation from the first dataset
> >> >>precedes the firstrowof the second dataset which inturn precedes the
> >> >>firstrowof the third dataset and so on.
>
> >> >>ie.
>
> >> >>table1 NEW
> >> >>DATASET
> >> >> obs num
> >> >>obs1 ------------------------------------> 1
> >> >>obs1 (table1)
> >> >>obs2
> >> >>obs3
> >> >>obs4
> >> >>obs5
>
> >> >>table2
>
> >> >>obs1 -------------------------------------> 2
> >> >>obs1 (table2)
> >> >>obs2
> >> >>obs3
> >> >>obs4
> >> >>obs5
>
> >> >>table3
>
> >> >>obs1 -----------------------------------------> 3
> >> >>obs1 (table3)
> >> >>obs2
> >> >>obs3
> >> >>obs4
> >> >>obs5 4
> >> >>obs2 (table1)
> >> >> 5
> >> >>obs2 (table2)
> >> >> 6
> >> >>obs2 (table3)
>
> >> >>.......and so on...........
>
> >> >>Can anyone please help me out on this.
>
> >> >>Thanks,
> >> >>Vikas- Hide quoted text -
>
> >> - Show quoted text -
>
> > Hi all,
>
> > Thank you for all your replies, much appreciated.
>
> > Special thanks to Nat as his suggestion works.
>
> > I also need to put a header and a trailer as the first and the last
> >rowin my final textfilewhich consists of these combined datsets,
>
> > such as header - AZ0983B765
>
> > |
> > |
>
> > tail - BZ127
>
> > Any suggestion will be highly appreciated.
>
> > Thanks- Hide quoted text -
>
> - Show quoted text -
Hey Karma,
This solution is great too, thanks for that much appreciated, any
ideas about my header and trailer issue mentioned earlier?
Thanks
|