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...
DDS Data Extraction
From: Michael S. Zdeb [mailto:msz03@HEALTH.STATE.NY.US]
Sent: Thursday, May 06, 2004 5:43 AM
Subject: Re: In Operator with numbers
Bonjour (practicing for SUGI)...
I' m not sure if anyone mentioned this yet. In V9, numeric ranges are
allowed with the IN operator, but the range requires a COLON...
length in_out $3;
input x @@;
if x in (1:5 10:14) then in_out='IN';
else in_out = 'OUT';
1 2 8 9 12 13
proc print data=test;
Obs in_out x
1 IN 1
2 IN 2
3 OUT 8
4 OUT 9
5 IN 12
6 IN 13
U@Albany School of Public Health
1 University Drive
Rensselaer, NY 12144-3456