Date: Wed, 4 Oct 2006 22:57:58 -0400
Reply-To: "Howard Schreier <hs AT dc-sug DOT org>" <nospam@HOWLES.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Howard Schreier <hs AT dc-sug DOT org>" <nospam@HOWLES.COM>
Subject: Re: If multiple condition.
On Wed, 4 Oct 2006 11:59:58 -0700, Terjeson, Mark <Mterjeson@RUSSELL.COM> wrote:
>Hi,
>
>Here is one way:
>
>
>
>data sample;
> input A B C D E;
>cards;
>5 39 9 58 33
>3 50 44 66 45
>33 50 12 44 22
>30 3 5 12 99
>2 44 11 33 90
>9 33 2 65 18
>44 25 2 11 44
>13 4 15 6 29
>;
>run;
>
> * datastep version ;
>data temp;
> set sample;
> length f $6;
> select;
> when (a>10 and c>10) f = put(e,2.);
> when (a>10 and c<10) f = put(b,2.);
> when (a<10 and c>10) f = put(d,2.);
> otherwise f = "Delete";
> end;
> if f ne 'Delete';
>run;
>
>proc sort data=temp out=result;
> by f;
>run;
>
>
>
> * SQL version ;
>proc sql;
> create table result2 as
> select
> *,
> case
> when (a>10 and c>10) then put(e,2.)
> when (a>10 and c<10) then put(b,2.)
> when (a<10 and c>10) then put(d,2.)
> else "Delete"
> end as f format=$6.
> from
> sample
> having
> f ne 'Delete'
> order by
> f
> ;
>quit;
>
>
>proc compare data=result compare=result2;
>run;
>
>
>Hope this is helpful.
>
>
>Mark Terjeson
In SAS you cannot mix numeric and character values in the same column.
That's why Mark converted numerics to character.
Here's a different way (for SAS V.9):
data temp(where=(not missing (f) ) );
set sample;
f =ifn(a>10 and c>10,e,
ifn(a>10 and c<10,b,
ifn(a<10 and c>10,d,.) ) );
run;
F is numeric. Notice that this is close to the Excel code in its structure.
I notice that all of the comparisons are strict inequalities. If there were
observations with A or C equal to the integer 10, they would be deleted.
>-----Original Message-----
>From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
>Aknas Dii
>Sent: Wednesday, October 04, 2006 11:08 AM
>To: SAS-L@LISTSERV.UGA.EDU
>Subject: If multiple condition.
>
>Below..I did on excel, but I have huge data set and would like to do
>similar in SAS;
>
>Here is the excel version formula in clumn "F".
>=IF(AND(A1>10,C1>10),E1,IF
>(AND(A1>10,C1<10),B1,IF(AND(A1<10,C1>10),D1,"Delete")))
>
>and produces clumn "F"
>
>A B C D E F
>5 39 9 58 33 Delete
>3 50 44 66 45 66
>33 50 12 44 22 22
>30 3 5 12 99 3
>2 44 11 33 90 33
>9 33 2 65 18 Delete
>44 25 2 11 44 25
>13 4 15 6 29 29
>
>And sort by clumn "F" and all the record that contains the word "
>delete".
>Final result looks like this.
>
>A B C D E F
>30 3 5 12 99 3
>33 50 12 44 22 22
>44 25 2 11 44 25
>13 4 15 6 29 29
>2 44 11 33 90 33
>3 50 44 66 45 66
>
>
>Any luck on how to code this on SAS, which can produce similar result.
>
>Thanks in advance.
>Dii
|