|Date: ||Thu, 6 Nov 1997 09:09:27 -0800|
|Reply-To: ||William Kreuter <email@example.com>|
|Sender: ||"SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>|
|From: ||William Kreuter <billyk@U.WASHINGTON.EDU>|
|Subject: ||Make Your Own Logical Operators (fwd)|
|Content-Type: ||TEXT/PLAIN; charset=US-ASCII|
The SAS-L to comp.soft-sys.sas link may be getting a little flaky
again. I've received word that although I posted the following
article last Sunday to the Usenet group, it hasn't yet appeared on
SAS-L. I apologize if this ends up duplicating anyone's traffic.
Also, I see that some of what I posted on Sunday was a little
confused, so I've improved it here.
---------- Forwarded message ----------
Date: Sun, 2 Nov 1997 15:50:37 -0800
From: William Kreuter <firstname.lastname@example.org>
Subject: Make Your Own Logical Operators (was Re: exclusive or)
I received several requests to re-post my old screed "Make Your Own
Logical Operators." I originally posted it on comp.soft-sys.sas on
July 24, 1994, and I re-posted it at least once after that. I think
that each time I posted it, the Usenet-to-SAS-L link went through one
of its periodic malfunctions, so many folks may not have seen this.
Here's a rewrite of what I posted in July, 1994.
I recently mentioned a standard shortcut to programming an
exclusive-or. Others of these shortcuts could be useful in various
applications. Here are the other possibilities. This list can be
created by using standard truth-table techniques from undergraduate
computer science. The idea is to find a numerical comparison of zero
(false) and one (true) that produces the result of the corresponding
Because missing and zero are both false but are not numerically equal
to each other, and because all values other than missing or zero are
true, these comparisons may only be correct when the only possible
values for A and B are zero and one. If in doubt, substitute "A and
1" for A, and "B and 1" for B. Alternatively, you could substitute
"^^A" for A, and "^^B" for B.
logical comparison shortcut longer equivalent
----------------------- -------- --------------------------
A exclusive-or B A^=B (A or B) and not (A and B)
A and B are either both
true or both false A=B (A and B) or (not A and not B)
A is true and B is false A>B A and not B
A is false and B is true A<B B and not A
A is true or B is false A>=B A or not B
B is true or A is false A<=B B or not A
Each of the above "logical comparisons" has a name in the philosophy
of logic, which I never studied. I think that A=B, for instance, is
called "A is equivalent to B", and A>B is called "A does not imply B".
Suppose you need to code a subsetting if to examine this condition: "P
is less than Q and R is less than S, or P is not less than Q and R is
not less than S." One could code this as:
if p<q & r<s | p>=q & r>=s;
However, I think it's more legible and will run better to use:
This might be even more useful if any of P, Q, R or S are expressions
instead of simple variables.
All of the preceding information may well be in some third-party SAS
book somewhere. A post with the title of such a reference would be
William Kreuter, Senior Computer Specialist, University of Washington
Ctr. for Cost & Outcomes Research, 146 N. Canal St. #300, Seattle, WA 98103
voice or voice mail: 206-543-5007 fax: 206-543-5318 mailstop: 358853