I call it "Boolean normalizing operator" because it turns any true value
(i.e. anything not zero and not missing) to 1 and any false value (i.e.
anything zero or missing) to 0. As _Null_ pointer out, same as mnemonic NOT
NOT. Hence the following, where X is a numeric expression,
bool = ^^ X ;
bool = not not X ;
are fully equivalent to
if X = 0 or missing (X) then bool = 0 ;
else bool = 1 ;
if X then bool = 1 ; else bool = 0 ;
Another clever trick from the same bag is
bool = X = -X ;
It comes with a slight marring side effect. I will leave it to SAS-L to
ponder which condition it tests for and what the side effect is. When, a
long time ago, I showed it to Bob Virgile (renowned for his deep
appreciatiion of such SAS artifacts) he called it "cute".
On Tue, 13 Oct 2009 07:40:52 -0400, Jack Clark <jclark@HILLTOP.UMBC.EDU>
>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.
>Senior Research Analyst
>University of Maryland, Baltimore County
>Sondheim Hall, 3rd Floor
>1000 Hilltop Circle
>Baltimore, MD 21250
>Confidentiality Notice: This e-mail may contain information that is legally
privileged and that is intended only for the use of the addressee(s) named
above. If you are not the intended recipient, you are hereby notified that
any disclosure, copying of this e-mail, distribution, or action taken in
reliance on the contents of this e-mail and/or documents attributed to this
e-mail is strictly prohibited. If you have received this information in
error, please notify the sender immediately by phone and delete this entire
e-mail. Thank you.-----Original Message-----
>From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
>Sent: Tuesday, October 13, 2009 1:41 AM
>Subject: Re: Determining if a character string includes a phrase
>Frankly, I fail to see why it seems to be difficult. Both INDEXw and
>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
> array phrase  ;
> 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.
>A much more interesting and involved question would be what is the most
>efficient way to confirm or reject the presence or the phrase
>"the Raven still sitting above my door, his eyes all dreaming"
>"And the Raven, never flitting, still is sitting, still is sitting on
>pallid bust of Pallas just above my chamber door, and his eyes have all
>seeming of the demon that is dreaming".