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 (January 2007, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 4 Jan 2007 14:59:37 -0500
Reply-To:     Dianne Rhodes <diannerhodes@COMCAST.NET>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Dianne Rhodes <diannerhodes@COMCAST.NET>
Subject:      Re: Is "NOT IN" an undocumented operator?
Comments: To: RHOADSM1@WESTAT.COM

On Thu, 4 Jan 2007 14:20:07 -0500, Mike Rhoads <RHOADSM1@WESTAT.COM> wrote:

>I was modifying a program written by somebody else earlier today, and >came across an IF-statement using "NOT IN". I thought I had remembered >at one point that this did not work, and so decided to (1) verify >whether it worked, and (2) check the documentation. The code below does >in fact work (in SAS 9.1.3 under WinXP): > >DATA _NULL_; >LENGTH Char1 $ 1 Result $ 5; >DO N = RANK('A') TO RANK('Z'); > Char1 = BYTE(N); > IF Char1 NOT IN ('A','E','I','O','U') THEN Result = 'False'; > ELSE Result = 'True'; > PUT Char1= Result=; >END; >RUN; > >According to the documentation, unless I'm either missing or misreading >something, I am surprised that this works. "IN" is documented as an >infix operator requiring an expression on the left and a list of values >on the right (and "Char1 NOT" is not an expression). "NOT" is >documented as a prefix operator that applies to the logical expression >that follows (and IN... by itself is not a logical expression). I >thought I had remembered that you had to write this like so: > >IF NOT(Char1 IN ('A','E','I','O','U')) ... > >which is more awkward but does match the documented behavior. > >This of course is in contrast to not-equals, which is documented as a >comparison operator. > >Not complaining, just wondering. > >Mike Rhoads >Westat >RhoadsM1@Westat.com

I have used IF NOT IN(...) for some time. But IN sometimes does some interpreting on its own, and does not complain. When I was still at Westat, we came across some code as

IF IN(1-5, 13-17); SAS did not complain. (Would have been version 6.12 or 8.2)

What it did do is:

IN saw it as IF IN(1, -5, 13, -17) which of course was not what we wanted. How long that code had been around I don't know. I suspect someone cut and pasted it from a format value statement, where it would have worked just fine.

Dianne at BLS


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