Date: Sun, 6 Mar 2011 22:25:34 +0000
Reply-To: "Keintz, H. Mark" <mkeintz@WHARTON.UPENN.EDU>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Keintz, H. Mark" <mkeintz@WHARTON.UPENN.EDU>
Subject: Re: Coalesce
In-Reply-To: <201103062129.p26BlS7C006641@willow.cc.uga.edu>
Content-Type: text/plain; charset="us-ascii"
Randy:
You didn't say what was wrong with your results, but I believe this does what you want to do:
data want;
set have;
if a=2 then c=coalesce(b,c);
else c=b;
retain c;
run;
I presume you forgot the ELSE statement.
Regards,
Mark
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Randy
Sent: Sunday, March 06, 2011 4:30 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Coalesce
My Data is as follows;
VarA VarB
1 5
1 2
1 3
2 3
2 .
2 .
1 5
1 9
2 9
1 5
1 7
2 7
2 .
2 .
and so on
My data should look as follows:
VarA VarB VarC
1 5 5
1 2 2
1 3 3
2 3 3
2 . 3
2 . 3
1 5 5
1 9 9
2 9 9
1 5 5
1 7 7
2 7 7
2 . 7
2 . 7
The code that I wrote is as follow:
data need ; set have;
RETAIN VarC ;
if VarA = 2 then do; VarC = Coalesce (VarB, VarC); end; run;
Where is the mistake that I am making?
Thank You;
Randy