|
Lassen's format suggestion is a good idea and results in a more readable code than if ... then statements.
You can make it even simpler as this :
proc format;
INvalue crank
50 <- 30000 = 0
30000<- 35000 = 3
35000<- 40000 = 2
40000<- 50000 = 1
other=-1
;
run;
data apcmlg;
set apcmlg;
if purseindex=1 then do;
crank=input(clmgprice,crank.);
c1rank=input(clmgprice1,crank.);
end;
else do;
crank=-1;
c1rank=-1;
end;
run;
-----Message d'origine-----
De : SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] De la part de Søren Lassen
Envoyé : jeudi 23 avril 2009 11:08
À : SAS-L@LISTSERV.UGA.EDU
Objet : Re: If, then statements
As you are doing the same logic for two sets of variables,
using a format is probably simpler after all:
proc format;
value crank
50 <- 30000 = '0'
30000<- 35000 = '3'
35000<- 40000 = '2'
40000<- 50000 = '1'
other='-1'
;
run;
data apcmlg;
set apcmlg;
if purseindex=1 then do;
crank=input(put(clmgprice,crank.),2.);
c1rank=input(put(clmgprice1,crank.),2.);
end;
else do;
crank=-1;
c1rank=-1;
end;
run;
Regards,
Søren
On Wed, 22 Apr 2009 19:44:59 -0400, Michael Bryce Herrington
<mherrin@G.CLEMSON.EDU> wrote:
>I am looking for something more simple than I have. I want to write a
data
>step that does the same thing the bellow code would do, but without having
>to write "if purseindex=1 and ..." before each statement.
>
>I was hoping something like:
>if purseindex=1 then
>if clmgprice>50 then Crank=1;
>
>Can you do this? Thanks!
> *
>
>data* apclmg;
>
>set apclmg;
>
>crank=-*1*;
>
>c1rank=-*1*;
>
>if purseindex=*1* and clmgprice>*50* then Crank=*0*;
>
>if purseindex=*1* and clmgprice1>*50* then C1rank=*0*;
>
>if purseindex=*1* and *40000*<clmgprice<=*50000* then Crank=*1*;
>
>if purseindex=*1* and *40000*<clmgprice1<=*50000* then C1rank=*1*;
>
>if purseindex=*1* and *35000*<clmgprice<=*40000* then Crank=*2*;
>
>if purseindex=*1* and *35000*<clmgprice1<=*40000* then C1rank=*2*;
>
>if purseindex=*1* and *30000*<clmgprice<=*35000* then Crank=*3*;
>
>if purseindex=*1* and *30000*<clmgprice1<=*35000* then C1rank=*3*;
>
>
>
>--
>Bryce Herrington
>Clemson University
>111 Briar Lane
>Central, SC 29630
>mherrin@g.clemson.edu
>(863) 258-4758
|