Date: Fri, 20 Mar 2009 04:19:18 -0400
Reply-To: Jim Groeneveld <jim.1stat@YAHOO.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Jim Groeneveld <jim.1stat@YAHOO.COM>
Subject: Re: Constructing Groups
Hi Randy,
You did not yet tell us how you would define groups. You just let us guess.
Assuming you define groups by both VarA and VarB you might have thought of
adapting Anindya's example code as:
data test2;
set test;
by VarA varB notsorted;
retain group 0;
if /*FIRST.VarA OR*/ first.varB then do;
group = group + 1;
varD = 0;
end;
run;
The code part /*FIRST.VarA OR*/ has been commented out. It would work well,
and it would be logically correct, but every time FIRST.VarA is 1 FIRST.VarB
is 1 as well, so it is redundant.
Does this do what you want? If not then tell us how to discriminate groups.
Regards - Jim.
--
Jim Groeneveld, Netherlands
Statistician, SAS consultant
home.hccnet.nl/jim.groeneveld
My computer, my wife and I will attend SGF 2009 near Washington.
On Fri, 20 Mar 2009 01:40:50 -0400, Randy <randistan69@HOTMAIL.COM> wrote:
>Dear Anindya:
>Your solution will not work correctly if the data set looks like:
>VarA VarB VarC
>905X3 9820 3
>905X3 9820 8
>905X3 9820 9
>97743 9820 4
>97743 9820 9
>905X3 9823 4
>905X3 9823 6
>905X3 9823 7
>98345 9823 3
>98345 9823 8
>Where there are two Different values of VarA for VarB 9820.
>The solution should be
>VarA VarB VarC Group VarD
>905X3 9820 3 1 0
>905X3 9820 8 1
>905X3 9820 9 1
>97743 9820 4 2 0
>97743 9820 9 2
>905X3 9823 4 3 0
>905X3 9823 6 3
>905X3 9823 7 3
>98345 9823 3 4 0
>98345 9823 8 4
>I think that an Ifn statement should be used..but I cannot figure out the
logic.
> Randy