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 1997, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Thu, 6 Nov 1997 09:09:27 -0800
Reply-To:   William Kreuter <billyk@u.washington.edu>
Sender:   "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:   William Kreuter <billyk@U.WASHINGTON.EDU>
Subject:   Make Your Own Logical Operators (fwd)
Comments:   To: "Zuckier, Gerald" <Zuckier@chime.org>
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.

Billy

---------- Forwarded message ---------- Date: Sun, 2 Nov 1997 15:50:37 -0800 From: William Kreuter <billyk@u.washington.edu> Newsgroups: comp.soft-sys.sas 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 logical comparison.

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".

Practical example. 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:

if (p<q)=(r<s);

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 welcome.

William Kreuter, Senior Computer Specialist, University of Washington Ctr. for Cost & Outcomes Research, 146 N. Canal St. #300, Seattle, WA 98103 billyk@u.washington.edu http://weber.u.washington.edu/~billyk/ voice or voice mail: 206-543-5007 fax: 206-543-5318 mailstop: 358853


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