Date: Sun, 28 Aug 2011 06:57:24 -0700
Reply-To: Jeremy Miller <qatman@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Jeremy Miller <qatman@GMAIL.COM>
Subject: Re: COALESCE Mistake?
In-Reply-To: <201108280048.p7RAu72Y007194@waikiki.cc.uga.edu>
Content-Type: text/plain; charset=ISO-8859-1
The listed data output seems off (the last five rows should have ones
instead of twos). It appears that you do not want to overwrite var_b.
Instead you want to set var_c = var_b but also keep the previous var_b value
if var_a = A. This code will do that.
data want;
set have;
retain var_c;
if not(var_a = 'A' and var_b = .) then var_c = var_b;
run;
Jeremy
On Sat, Aug 27, 2011 at 17:48, SUBSCRIBE SAS-L Anonymous <
randistan69@hotmail.com> wrote:
> This is a sample of the data
>
> Var_A Var_B
> B .
> B 2
> B 1
> A 1
> A .
> B .
> B 2
> A 2
> B .
> B 1
> A 1
> A .
> A .
>
> What I want is :
>
> Var_A Var_B VarC
> B . .
> B 2 2
> B 1 1
> A 1 1
> A . 1
> B . .
> B 2 2
> A 2 2
> B . .
> B 2 2
> A 2 2
> A . 2
> A . 2
>
>
> Thank You.
> Randy
>
>
> On Sat, 27 Aug 2011 19:27:57 -0500, Joe Matise <snoopy369@GMAIL.COM>
> wrote:
>
> >You're going to have to give just a tad more information than that. What
> >are you actually trying to do?
> >
> >What you did:
> >* If varA = A then VarC equals VarB if it is not missing, otherwise it
> keeps
> >its previous value.
> >* If varA ne A then VarC equals VarB whether or not VarB is missing.
> >* VarB is set equal to VarC, which means that if VarB is not missing it is
> >left equal to itself, and if VarB is missing and VarA = 'A' then VarB will
> >be equal to the previous iteration VarC.
> >
> >Is that what you wanted to do?
> >
> >-Joe
> >
> >On Sat, Aug 27, 2011 at 7:23 PM, Randy <randistan69@hotmail.com> wrote:
> >
> >> Dear All:
> >> Here is the code that I have written:
> >>
> >> data want ; set need;
> >> if VarA = 'A' then VarC = COALESCE (VarB, VarC);
> >> else VarC = VarB;
> >> VarB = VarC;
> >> RETAIN VarC ;
> >> run;
> >>
> >> Is this correct? Can I omit the VarB = VarC statement;
> >> Randy
> >>
>
|