Date: Thu, 2 Jun 2011 08:54:18 -0500
Reply-To: Joe Matise <snoopy369@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Joe Matise <snoopy369@GMAIL.COM>
Subject: Re: A datastep question
In-Reply-To: <201106021348.p522DhMq020808@waikiki.cc.uga.edu>
Content-Type: text/plain; charset=ISO-8859-1
First off, you're not deleting records in the second one. The subsetting
IFs in the first one (and the DELETEs of course) remove records, while in
the second you are just setting LB=1 and ignoring the deletes.
I would also word the statement slightly differently.
if (dr in (1,2) and pa='Y' and not (tr in ('1','2','3','4','5') or (tr in
('11','12') and xp=2)));
That's a bit easier to read - rather than distributing the not all over the
place, you specify that a group of things is not true. Humans read positive
things more easily than negative things, so distributing it makes it harder
to read.
-Joe
On Thu, Jun 2, 2011 at 8:48 AM, Tom Smith <need_sas_help@yahoo.com> wrote:
> I have a following datastep:
>
> data xx;
> set yy;
> if dr in (1 2);
> if pa='Y';
> if tr in ('1' '2' '3' '4' '5' )then delete;
> if tr in ('11' '12') and xp=2 then delete;
> lb=1;
> run;
>
> I tried to short cut it as below, but some where I made the logic wrong,
> Can anyone please look at it and say where I might have made that mistake:
>
> data xx;
> set yy;
> if (dr in (1 2) and pa='Y' and tr not in ('1' '2' '3' '4'
> '5' )and (tr not in ('11' '12') and xp ne 2)) then lb=1;
> run;
>
> Thanks you so much
>
|