Date: Tue, 13 Oct 2009 12:03:44 -0700
Reply-To: "Schwarz, Barry A" <barry.a.schwarz@BOEING.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Schwarz, Barry A" <barry.a.schwarz@BOEING.COM>
Subject: Re: Determining if a character string includes a phrase
In-Reply-To: <456B52C41B724C41B96561D7AD283E7D01F04955@mail.chpdm.umbc.edu>
Content-Type: text/plain; charset="us-ascii"
The caret is the logical not operator. (SAS also supports other characters for this operator for people with other keyboards.) If the operand evaluates to zero, then the expression evaluates to one; otherwise the expression evaluates to zero. The effect of a double not is to map zero to zero (0 -> 1 -> 0) and non-zero to one (x -> 0 -> 1).
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Jack Clark
Sent: Tuesday, October 13, 2009 4:41 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: Determining if a character string includes a phrase
Paul,
Will you explain the double caret operator from your solution below? I
see that it is returning a 1 or 0 instead of the position in the string
normally returned by INDEXW, but I am not familiar with the operator.
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
Paul Dorfman
Sent: Tuesday, October 13, 2009 1:41 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: Determining if a character string includes a phrase
Kevin,
Frankly, I fail to see why it seems to be difficult. Both INDEXw and
FINDx
functions are suited for the task, e.g.:
data _null_ ;
input text $64. ;
text = translate (text, " ", ".,") ;
array pp $ 64 p1-p3 ("the train", "the station", "and i wasn't on
it") ;
array phrase [3] ;
do over pp ;
phrase[_i_] = ^^ indexw (upcase (text), upcase (strip (pp))) ;
end ;
put phrase[*] ;
cards ;
The train left the station, and I wasn't on it.
I wasn't on it when the train left the station.
The station was empty: the train had left without me.
;
run ;
|