As the first step in the decommissioning of sasCommunity.org the site has been converted to read-only mode.

Here are some tips for How to share your SAS knowledge with your professional network.

# Truth Table

From sasCommunity

Revision as of 10:54, 31 August 2017 by Ron.Fehd.macro.maven (Talk | contribs)

Author: Ronald_J._Fehd

## Truth Table

This program shows how to write statements which implement the following types of logic:

- boolean, binary-valued: in (0,1)
- DeMorgan's Laws
- fuzzy : in (0,0.5,1)
- trinary: in (.,0,1)

/*name : TruthTable description: make data set of values and logical combinations purpose : illustrate binary and trinary logical evaluation RJF2 2003May27 DeMorgan's Laws: ~(p ^ q) <=> ~p v ~q ~(p v q) <=> ~p ^ ~q tilde ~ :: not caret ^ :: and v :: or <=> :: is equivalent to not (p and q) <=> not p or not q not (p or q) <=> not p and not q *** ................................. */ %Let ProgName = TruthTable; %Let List = .,0 ,1; %Let List = 0,0.5,1; %Let List = 0 ,1; Title "&Progname. with P and Q in (&List.)"; PROC Format; value TF . = 'NA' 0 = 'F' 1 = 'T' other = '?';*between zero and one; DATA Truth_Table; length default = 4; label P = 'P' Q = 'Q' notP = 'not P' and = 'and(P,Q)' or = 'or(P,Q)' bxor = 'bxor(P,Q)' xor1 = 'xor(P,Q)' xor2 = 'xor(P,Q)' xor3 = 'xor2 no parens' DeM1a = 'not( and(P,Q) )' DeM1b = 'notP or notQ' DeM2a = 'not( or(P,Q) )' DeM2b = 'notP and notQ' FLmin = 'fuzzy logic and min(P,Q)' FLmax = 'fuzzy logic or max(P,Q)' FLnotP = 'fuzzy logic not 1 - P' ; format _numeric_ TF.; do P = &List.; do Q = &List.; notP = not P; and = P and Q; or = P or Q; bxor = bxor(P,Q); xor1 = P and not Q or not P and Q; xor2 = not(P and Q) and not(not P and not Q); xor3 = not P and Q and not not P and not Q ; DeM1a = not(P and Q); DeM1b = not P or not Q; DeM2a = not(P or Q); DeM2b = not P and not Q; FLmin = min(P,Q); FLmax = max(P,Q); FLnotP = 1 - P; output; end;*do Q; end; *do P; stop; run; PROC Print data = Truth_Table label noobs; run;

## References

- De Morgan's Laws: nand and nor
- Fehd
- Fuzzy Logic: ternary (trinary) values

-- created by User:Rjf2 10:26, 20 August 2007 (EDT)