@eqna |

Tests for equality of values.

Syntax: @eqna(arg1, arg2)

arg1: number or string

arg2: number or string

Return: number

Tests for equality of the arg1 and arg2, treating NAs and null strings as ordinary, and not as missing values. Simple equality testing which propagates null string NAs may be performed using the “=” binary comparison operator.

Return value is an integer (0, 1). Arguments which test as equal return a 1, and 0 otherwise.

When used with series objects, the test is performed for every observation in the workfile sample. Note that when used with matrix objects, the comparison is an equality test of all of the elements of the two matrices, and will return 0 if any element comparison is false. Individual element tests are available in
@eeqna

Examples

The test

scalar f = @eqna(NA, 2)

returns the value 0, not an NA.

Consider the comparison

vector v1 = @fill(1, 2, 2)

scalar f2 = @eqna(v1, 2)

compares the entire vector V1 to 2, and returns 0 since some of the elements of V1 are not equal to 2. Note that the comparison is an equality test of the entire vector that returns a 0 if any element is not equal, and a 1 if all elements are equal, ignoring NAs.

If SER1 and SER2 are numeric series,

series s2 = @eqna(ser1, ser2)

tests SER1 and SER2 for equality, ignoring NAs, for each observation in the workfile sample.

Define the string objects

string s1 = "abc"

string s2 = ""

Then

scalar b1 = @eqna("abc", "abc")

scalar b2 = @eqna("abc", s1)

sets the scalar objects B1 and B2 to 1, while

scalar c1 = @eqna("", "def")

scalar c2 = @eqna(s2, "def")

scalar c3 = @eqna(s1, s2)

sets C1, C2, and C3 to 0.

If ALPHA1 and ALPHA2 are alpha series,

series d1 = @eqna(alpha1, "abc")

series d2 = @eqna(alpha1, s1)

series d3 = @eqna(alpha1, alpha2)

perform the equality test using ALPHA1 and ALPHA2 for each observations in the workfile sample.

If SVEC1 and SVEC2 are svectors,

scalar sc1 = @eqna(svec1, "abc")

scalar sc2 = @eqna(svec1, svec2)

perform the equality test of SVEC1 against “abc”, and the contents of SVEC2. Note that this is a full equality test of SVEC1 against the string, or against each element of SVEC2, and that the test will return a 0 if any element is not equal, and a 1 if all elements are equal (ignoring empty strings).

Cross-references