Date: Mon, 30 Jul 2001 11:12:07 -0400
Reply-To: "Diskin, Dennis" <Dennis.Diskin@PHARMA.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Diskin, Dennis" <Dennis.Diskin@PHARMA.COM>
Subject: Re: If vs. Where in Selection
Content-Type: text/plain
Loren,
The only problem I see here is that your informat is not wide enough.
Differing from formats, you need to either use the LENGTH option, or make at
least one left hand side value as long as the longest actual data.
The result in this case is that the informat maps all three values using
only the first 5 characters so they all map to 1.
I can't otherwise duplicate your stated problem in v6.12 under unix.
hth,
Dennis Diskin
Sample:
data testdata;
length codevar $6;
input codevar;
cards;
63090
63090X
63090C
;
run;
proc format;
invalue code
'63090 ' = 1
other = 0;
run;
data itest;
set testdata;
* where input(codevar,code.);
if input(codevar,code.);
run;
data wtest;
set testdata;
where input(codevar,code.);
* if input(codevar,code.);
run;
Result:
16
17 data itest;
18 set testdata;
19 * where input(codevar,code.);
20 if input(codevar,code.);
21 run;
NOTE: The data set WORK.ITEST has 1 observations and 1 variables.
NOTE: DATA statement used:
real time 0.15 seconds
cpu time 0.03 seconds
22
23 data wtest;
24 set testdata;
25 where input(codevar,code.);
26 * if input(codevar,code.);
27 run;
NOTE: The data set WORK.WTEST has 1 observations and 1 variables.
NOTE: DATA statement used:
real time 0.16 seconds
cpu time 0.02 seconds
> -----Original Message-----
> From: Loren Lidsky [SMTP:llidsky@MECF.ORG]
> Sent: Monday, July 30, 2001 10:38 AM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: If vs. Where in Selection
>
> Hi All,
>
> I'm sure this was covered (way back) when 'where' was new but...
>
> I was wondering if someone could explain why the following code snippet
> picks up, for example,
>
> 63090
> 63090X
> 63090C
>
> using the subsetting if and only picks up
>
> 63090
>
> using the where clause.
>
> I suspect it has something to do with the way SAS sets lengths of
> variables in the PDV (if statement) and sets lengths when
> 'preprocessing' using the where.
>
> proc format;
> invalue code
> '63090' = 1
> other = 0;
> run;
>
> data codetest;
> set testdata;
> * where input(codevar,code.);
> if input(codevar,code.);
> run;
>
> Thanks for any input!
>
> Loren Lidsky
> Director of Information Systems
> Mass Extended Care Federation
> Newton Lower Falls, MA
|