LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (May 2004, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 7 May 2004 13:44:29 -0700
Reply-To:     cassell.david@EPAMAIL.EPA.GOV
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 example > of Ian-invented term "wallpaper", that is it). The most SAS-centric approach > would be, as others have pointed out, to store the values in a file and then > > reading the latter to either create a quoted IN-list as a value assigned to > a macro variable via SQL, or (which I would prefer) to create a format. This > would separate the code (what to do with data) from the hard-coded values > (the data themselves). > > However, even if you feel you must use a hard-coded list, there is a way to > 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 more > rapidly, too. SAS string-searching functions algorithms quite faster than > 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 database. 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 incorrect string looks like:

4 3

Uh-oh. That was just accepted as legit by the INDEX() approach above. You have to make sure that chunks of your index string cannot be illegal character strings. The first version (if v1 in ...) doesn't have this problem. If you can't bear the shame of wallpaper in your code, then check your variable using a format instead.

HTH, David -- David Cassell, CSC Senior computing specialist mathematical statistician

Back to: Top of message | Previous page | Main SAS-L page