Date: Fri, 7 May 2004 13:44:29 -0700
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "David L. Cassell" <cassell.david@EPAMAIL.EPA.GOV>
Subject: Re: In Operator with numbers
Content-type: text/plain; charset=US-ASCII
"Choate, Paul@DDS" <pchoate@DDS.CA.GOV> quoted the legendary P. Dorfman:
> A related snipet from a recent Paul Dorfman post:
> I find IN-lists with myriads of quoted character values, such as
> if v1 in ('123' '234' '345' '456' '567' '678' '789' '890') then...
> inconvenient and making the program hard to read (If you want a real
> of Ian-invented term "wallpaper", that is it). The most SAS-centric
> would be, as others have pointed out, to store the values in a file
> reading the latter to either create a quoted IN-list as a value
> a macro variable via SQL, or (which I would prefer) to create a
> would separate the code (what to do with data) from the hard-coded
> (the data themselves).
> However, even if you feel you must use a hard-coded list, there is a
> make it more tidy than ibid.:
> if index (v1, '123 234 345 456 567 678 789 890') then...
> Not only you rid the code from the gazillion of quotes, it will run
> rapidly, too. SAS string-searching functions algorithms quite faster
> the linear search used by the IN operator...
The suggestion by Paul (Dorfman) has one major problem. Which I had the
misfortune to encounter while error-checking some data from a GIS
I was looking for character categories which would seem to fit into the
above strategy. But what happens when you use the above line and one
string looks like:
Uh-oh. That was just accepted as legit by the INDEX() approach above.
have to make sure that chunks of your index string cannot be illegal
strings. The first version (if v1 in ...) doesn't have this problem.
can't bear the shame of wallpaper in your code, then check your variable
a format instead.
David Cassell, CSC
Senior computing specialist