Date: Thu, 23 Apr 2009 11:29:46 -0400
Reply-To: Nathaniel.Wooding@DOM.COM
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Nat Wooding <Nathaniel.Wooding@DOM.COM>
Subject: Re: If, then statements
In-Reply-To: <e52cf8710904230809h5a6db9acna0241cddd96fcbb0@mail.gmail.com>
Content-Type: text/plain; charset="ISO-8859-1"
Michael
One way to simply your code would be to change
if racetype1='A' or racetype1='AO' or racetype1='CO' or racetype1='R'
or racetype1='T' or racetype1='F' then allwclmg=*1*;
else allwclmg=*0*;
to
if racetype1 in( 'A' , 'AO' , 'CO' ,'R' , 'T' , 'F') then allwclmg= 1 ;
else allwclmg=*0*;
EG
data m;
input racetype1 $2.;
if racetype1 in( 'A' , 'AO' , 'CO' ,'R' , 'T' , 'F') then allwclmg= 1 ;
cards;
A
B
AC
AO
CO
R
TF
1F
PROC PRINT;RUN;
Nat Wooding
Environmental Specialist III
Dominion, Environmental Biology
4111 Castlewood Rd
Richmond, VA 23234
Phone:804-271-5313, Fax: 804-271-2977
Michael Bryce
Herrington
<mherrin@G.CLEMSO To
N.EDU> SAS-L@LISTSERV.UGA.EDU
Sent by: "SAS(r) cc
Discussion"
<SAS-L@LISTSERV.U Subject
GA.EDU> Re: If, then statements
04/23/2009 11:09
AM
Please respond to
Michael Bryce
Herrington
<mherrin@G.CLEMSO
N.EDU>
Hey, Thanks to all for the input. Some of this talk near the end went over
my head. The input(put(clmgprice,crank.),2.) method did not work, and I
guess I am too amateur to figure out why. The error was
ERROR 48-59: The format CRANK was not found or could not be loaded.
But this is what I ended up with for now. I will have to repeat this
portion of code(plus some more stuff) 48 times, for 48 different tracks,
because the ranges on the format section will change by track, so if anyone
knows a more efficient manner in doing it your thoughts are appreciated.
(I
guess without seeing the data it is harder to get a feel for also, sorry).
Also is this note about converting numeric values to character values a
problem? The arithmatic worked out after this note appeared. Thanks
again.
*
data* apclmg;
set apclmg;
if racetype1='A' or racetype1='AO' or racetype1='CO' or racetype1='R'
or racetype1='T' or racetype1='F' then allwclmg=*1*;
else allwclmg=*0*;
if racetype1='M' or racetype1='MO' or racetype1='S' then mdnclmg=*1*;
else mdnclmg=*0*;
if racetype1='N' or racetype1='G1' or racetype1='G2' or racetype1='G3'
or racetype1='NO' then stkclmg=*1*;
else stkclmg=*0*;
if track1='HAW' then purseindex=*1*;
* Same track/circut class change variables;
* Purse index already =1 for same track;
*
run*;
*make format for clmgprice1 and clmgprice;
*
proc* *format*;
INvalue crank
*0*<- *4000* = *14
*
*4000*<- *5000* = *13
*
*5000*<- *7500* = *12
*
*7500*<- *10000* = *11
*
*10000* = *10
*
*10000*<- *12500* = *9
*
*12500*<- *15000* = *8
*
*15000*<- *17500* = *7
*
*17500*<- *20000* = *6
*
*20000*<- *25000* = *5
*
*25000*<- *30000* = *4
*
*30000*<- *35000* = *3
*
*35000*<- *40000* = *2
*
*40000*<- *50000* = *1
*
*50000* < =*0
*
other=-*1
*
;
*
run*;
*
data* apclmg;
set apclmg;
if purseindex=*1* then do;
crank=input(clmgprice,crank.);
c1rank=input(clmgprice1,crank.);
end;
else do;
crank=-*1*;
c1rank=-*1*;
end;
clmgchange=Crank-C1rank;
*indicate an climb or drop in class for claiming races only
and at comparable tracks only;
if purseindex=*1* then do;
if clmgchange=*0* then sameclmg=*1*;
else sameclmg=*0*;
if clmgchange=-*1* then clmgup1=*1*;
else clmgup1=*0*;
if clmgchange<=-*2* then clmgup2=*1*;
else clmgup2=*0*;
if clmgchange=*1* then clmgdn1=*1*;
else clmgdn1=*0*;
if clmgchange>=*2* then clmgdn2=*1*;
else clmgdn2=*0*;
end;
* set clmg change variables =0 for shippers
they will be handled separately later;
else do;
sameclmg=*0*;
clmgup1=*0*;
clmgup2=*0*;
clmgdn1=*0*;
clmgdn2=*0*;
end;
*If a horse is not moving within claiming races the clmg change variables
should equal zero;
***This could be improved and removed somehow***;
if allwclmg=*1* or mdnclmg=*1* or stkclmg=*1* then do;
sameclmg=*0*;
clmgup1=*0*;
clmgup2=*0*;
clmgdn1=*0*;
clmgdn2=*0*;
end;
*
run*;
2009/4/23 ./ ADD NAME=Data _null_; <iebupdte@gmail.com>
> On 4/23/09, Søren Lassen <s.lassen@post.tele.dk> wrote:
> > Yes, the informat solution leads to slightly simpler code.
> > But they also generate a
> > NOTE: Numeric values have been converted to character values...
>
> I agree, when the object of the coding is a numeric variable(value);
> PUT() with numeric format followed by INPUT() on the result, when
> numeric result is desired, seems more natural.
>
> The SAS conversion using BEST12. format may produce an unexpected
> undesirable result when read with INFORMAT.
>
> In other words do you want to?
>
> input(put(num,w.d),recodeinformat.);
> input(cats(num),recodeinformat.);
> input(vvalue(num),recodeinformat.);
> or
> input(put(num,recodeformat),w.d);
>
>
> Like Howard said we need an INFORMAT type that takes numeric argument.
>
--
Bryce Herrington
Clemson University
111 Briar Lane
Central, SC 29630
mherrin@g.clemson.edu
(863) 258-4758
CONFIDENTIALITY NOTICE: This electronic message contains
information which may be legally confidential and or privileged and
does not in any case represent a firm ENERGY COMMODITY bid or offer
relating thereto which binds the sender without an additional
express written confirmation to that effect. The information is
intended solely for the individual or entity named above and access
by anyone else is unauthorized. If you are not the intended
recipient, any disclosure, copying, distribution, or use of the
contents of this information is prohibited and may be unlawful. If
you have received this electronic transmission in error, please
reply immediately to the sender that you have received the message
in error, and delete it. Thank you.