**Date:** Thu, 25 Jun 2009 06:20:57 -0700
**Reply-To:** Amar Mundankar <amarmundankar@GMAIL.COM>
**Sender:** "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
**From:** Amar Mundankar <amarmundankar@GMAIL.COM>
**Organization:** http://groups.google.com
**Subject:** Re: Split Dataset
**Content-Type:** text/plain; charset=ISO-8859-1
On Jun 25, 12:22 pm, ash007 <RamsamyAsh...@gmail.com> wrote:
> Hello SasUsers,
>
> I have a dataset which have a variable named X, this numeric variable
> has either '1', '0' or '.'.
>
> I want to split this dataset in order to have several dataset between
> 1 and 0.
>
> X
> .
> .
> .
> 1
> .
> .
> 0
> 1
> .
> .
> .
> .
> 0
> .
> .
>
> I want to have in this case 2 datasets :
>
> dst_1
> X
> 1
> .
> .
> 0
>
> dst_2
> X
> 1
> .
> .
> .
> .
> 0
>
> Thanks.
>
> Ash007.

Hi Ash007,
You can try the following code. But for the code below you should
initially know that there are only two combinations of 1 and 0 . I
mean, you should initially know that you have to create only 2
datasets.
I am preparing a macro for the below code which will be independent of
the number of combinations. So we dont need to know how many
combinations are there. The macro will take care of it.

data one ;
input x ;
cards;
.
.
.
1
.
.
0
1
.
.
.
.
0
.
.
;
data first(drop = flag) second(drop = flag) ;
retain flag 0;
set one;
if x = 1 and flag = 0 then do;
output first;
flag = 1;
return;
end;
if flag = 1 and (x = 0 or x = .) then do ;
output first;
if x = 0 then flag = 2;
return;
end;

if x = 1 and flag = 2 then do;
output second;
flag = 3;
return;
end;
if flag = 3 and (x = 0 or x = .) then do ;
output second;
if x = 0 then flag = 4;
return;
end;

run;
proc print data = first;
run;
proc print data = second;
run;

Thanks and Regards,
Amar Mundankar.