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 2011, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 18 Nov 2011 00:47:40 +0000
Reply-To:     "Nordlund, Dan (DSHS/RDA)" <NordlDJ@DSHS.WA.GOV>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Nordlund, Dan (DSHS/RDA)" <NordlDJ@DSHS.WA.GOV>
Subject:      Re: when to use OR vs AND with Multiple IF statements
In-Reply-To:  <587F57B26FAA8246A81D10D251EB8AB40296A818E7@EXCH07.GHCMASTER.GHC.ORG>
Content-Type: text/plain; charset=utf-8

> -----Original Message----- > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of > Pardee, Roy > Sent: Thursday, November 17, 2011 4:14 PM > To: SAS-L@LISTSERV.UGA.EDU > Subject: Re: when to use OR vs AND with Multiple IF statements > > Re: the colon-modified in operator--can you not put values of different > lengths in the in-set? That is, would: > > if dx_code1 in: ('410' '411' '412' '413' '416' '425' '414.0' '414.1') > ; > > Not work properly? > > Thanks! > > -Roy > > > Roy Pardee | DATA WRANGLER > Group Health Research Institute

Yes, that will work just fine. I just want to add one caution. SASers new to the IN: operator sometimes don't realize that the comparison is made up to the length of the shorter of the two strings being compared. So for example, if dx_code1 = '414', the above comparison will evaluate to TRUE. If dx_code1 = '414.19', the comparison will also be TRUE.

Hope this is helpful,

Dan

Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204

> -----Original Message----- > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of > toby dunn > Sent: Tuesday, October 18, 2011 9:05 AM > To: SAS-L@LISTSERV.UGA.EDU > Subject: Re: when to use OR vs AND with Multiple IF statements > > This is where I think the colon modifier comes in handy to hel clean up > the code to be more readable. > > If ( DX_Code1 In: ( '410' '411' '412' '413' '416' '425' ) ) Or > ( DX_Code2 In: ( '410' '411' '412' '413' '416' '425' ) ) Or > ( DX_Code3 In: ( '410' '411' '412' '413' '416' '425' ) ) Or > ( DX_Code1 In: ( '414.0' '414.1' ) ) Or > ( DX_Code2 In: ( '414.0' '414.1' ) ) Or > ( DX_Code3 In: ( '414.0' '414.1' ) ) ; > > > Or If you want fewer lines of codes, I havent tested it to see if it > actually runs faster buts its 2 function calls rather than 6: > > If ( PrxMatch( '/\b(?:410|411|412|413|416|425|414.0|414.1)\b/o' , CatX( > ' ' , DX_Code1 , DX_Code2 , DX_Code3 ) ) ; > > > > > > > If ( '01Sep10'd Le Test_Date Le '30Jun11'd ) > And > Result In : ( '1' '2' '3' '4' '5' '6' '7' '8' '9' '>' '<' ) ; > > > > > > > > Toby Dunn > > > If you get thrown from a horse, you have to get up and get back on, > unless you landed on a cactus; then you have to roll around and scream > in pain. > > “Any idiot can face a crisis—it’s day to day living that wears you out” > ~ Anton Chekhov > > > > > Date: Tue, 18 Oct 2011 11:46:28 -0400 > > From: kibrown@LADHS.ORG > > Subject: when to use OR vs AND with Multiple IF statements > > To: SAS-L@LISTSERV.UGA.EDU > > > > Hi all, > > How does multiple if statements work? Does it work like “AND” or > “OR”? > > when to use OR vs AND? > > > > I had three if statements in two different programs: > > I had this: > > if (substr(dx_code1,1,3) in ('410','411','412','413','416','425')) OR > > (substr(dx_code1,1,5) in ('414.0','414.1')); > > > > IF (substr(dx_code2,1,3) in ('410','411','412','413','416','425')) OR > > (substr(dx_code2,1,5) in ('414.0','414.1')) > > > > If (substr(dx_code3,1,3) in ('410','411','412','413','416','425')) OR > > (substr(dx_code3,1,5) in ('414.0','414.1')) ; Changed it to this: > > if (substr(dx_code1,1,3) in ('410','411','412','413','416','425')) OR > > (substr(dx_code1,1,5) in ('414.0','414.1')) OR > > (substr(dx_code2,1,3) in ('410','411','412','413','416','425')) OR > > (substr(dx_code2,1,5) in ('414.0','414.1')) OR > > (substr(dx_code3,1,3) in ('410','411','412','413','416','425')) OR > > (substr(dx_code3,1,5) in ('414.0','414.1')) > > > > This one I had two if statements: > > I had this: > > if '01Sep10'd le test_date le '30jun11'd; if substr(result,1,1) in > > ('1','2','3','4','5','6','7','8','9','>','<'); > > > > Changed to this > > if ('01Sep10'd le test_date le '30jun11'd) AND (substr(result,1,1) in > > ('1','2','3','4','5','6','7','8','9','>','<'));; > > both examples I got the same numbers > > > Group Health is people-powered: Join the conversation at: > http://www.choosegrouphealth.org > > GHC Confidentiality Statement > > This message and any attached files might contain confidential > information protected by federal and state law. The information is > intended only for the use of the individual(s) or entities originally > named as addressees. The improper disclosure of such information may be > subject to civil or criminal penalties. If this message reached you in > error, please contact the sender and destroy this message. Disclosing, > copying, forwarding, or distributing the information by unauthorized > individuals or entities is strictly prohibited by law.


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