Date: Wed, 19 Nov 2003 15:21:13 -0700
Reply-To: Jack Hamilton <JackHamilton@FIRSTHEALTH.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Jack Hamilton <JackHamilton@FIRSTHEALTH.COM>
Subject: Re: Lack of macro "in" function
Content-Type: text/plain; charset=us-ascii
One way is to use the index function. Choose for a delimiter a
printable character that's not in your data. Put the values you want to
look for into a string, separated by that delimiter. Here's an
example:
=====
22 %macro test;
23
24 %let values = |a|c|e|;
25
26 %let checkfor = x;
27
28 %if %sysfunc(index(&VALUES., |&CHECKFOR.|)) > 0 %then
29 %put INFO: Value &CHECKFOR found in list;
30 %else
31 %put INFO: Value &CHECKFOR *not* found in list;
32
33 %let checkfor = a;
34
35 %if %sysfunc(index(&VALUES., |&CHECKFOR.|)) > 0 %then
36 %put INFO: Value &CHECKFOR. found in list;
37 %else
38 %put INFO: Value &CHECKFOR. *not* found in list;
39
40 %mend test;
41
42 %test;
INFO: Value x *not* found in list
INFO: Value a found in list
=====
--
JackHamilton@FirstHealth.com
Manager, Technical Development
Metrics Department, First Health
West Sacramento, California USA
>>> "SAS User" <sas@SDAC.HARVARD.EDU> 11/19/2003 12:52 PM >>>
SAS-Lers,
To my understanding and through my experiences, there is no equivalent
of the statement: if var1 in (one, two, three); in the macro
language.
If I have a huge list that I need to check if a macro variable has one
of the values, instead of using several "or"s (%if &MVAR = one or
%MVAR = two or &MVAR = three) I use a data _null_ and another
macro var to flag if that's true. Does anyone have any other tricks
or am I just plain wrong in believing there is no "in" statement
for the macro language? Thanks.
-Casey
|