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 (November 2003, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 19 Nov 2003 17:30:20 -0500
Reply-To:     SAS User <sas@SDAC.HARVARD.EDU>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         SAS User <sas@SDAC.HARVARD.EDU>
Subject:      Re: Lack of macro "in" function
Comments: To: Jack Hamilton <JackHamilton@FIRSTHEALTH.COM>
In-Reply-To:  <sfbb8a7e.069@SLCM02.firsthealth.com>
Content-Type: TEXT/PLAIN; charset=US-ASCII

Just what I was looking for - thank you!

-Casey

On Wed, 19 Nov 2003, Jack Hamilton wrote:

> 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 >


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