# Basic logic syntax

The most basic syntax of a logic statement includes the variable name or record number, column location and the value in this format:

VARIABLE (VALUE) or RECORD/COLUMN (VALUE)

For example:

AGE (7) or 1/5 (7)

represents, ‘the variable AGE, a value of 7, or record 1, column 5, a value of 7.’ Most variables are more complex than the above example. The more complete syntax of a logic statement is:

AGE (VALUE1-VALUE2, VALUE3, VALUE4...) or RECORD/COLUMN:WIDTH (VALUE1-VALUE2, VALUE3, VALUE4...)

In the above syntax, ‘WIDTH’ accommodates fields whose values are stored in more than one column, such as the value ‘123,’ which would be stored in a 3-column field. The maximum WIDTH is 12; you don't need to specify widths of 1.

Variable data does not require syntax that includes the 'WIDTH' parameter (i.e. AGE (VALUE1-VALUE2, VALUE3, VALUE4...).

When working with ASCII, you can specify logic without specifying the record each time. You can use ‘record image’ or ‘offset mode.’ For example, the record image: 1/20 can be represented as: 20. If you have two records, each with 80 columns and you want to refer to the second record, tenth position, the record image would be: 2/10 and the offset mode would be: 90.

(VALUE) can be 0-9, A-Z (upper case only), negative numbers and decimal numbers.

When creating rows for a table whose rows all use the same record/position, you need only specify the record/position for the first row. Subsequent rows can include just the value.

Use of optional spacing:

For readability, adding one or more spaces between the variable and value or the position and the value is optional. For example:

GENDER(1) and GENDER (1)

or:

1/5(7) and 1/5 (7)

are equivalent.

Some ASCII files have multiple records for each case. For all other files that have only a single record per case, you can omit the record number when writing logic. Both statements are equivalent for files having a single record per case:

1/5(7)       5(7)

Following are a variety of examples of basic logic statements:

Multi-position fields are indicated by a colon:

Example:

1/5:2(12)

represents “record 1, starting in position 5, field width of 2, value 12” (the number following the colon indicates the field width). When no colon is included, a single position field width is assumed.

A range of values is indicated by a dash:

Example 1:

MARKET (12-14)

represents “variable MARKET, value of 12 or 13 or 14.” The dash between values indicates that a range of values will satisfy this statement. The dash represents OR logic, discussed later in this section.

Example 2:

1/5:2 (12-14)

represents “record 1, positions 5 and 6 (the field width is 2 starting at position 5), value of 12 OR 13 OR 14.” The dash between values indicates that a range of values will satisfy this statement. The dash represents OR logic, discussed later in this section.

Example 3:

SEGMENT (A-D)

represents “variable SEGMENT, value of A or B or C or D.” The dash between values indicates that a range of values will satisfy this statement. The dash represents OR logic, discussed later in this section.

 Note: When the range of values involves alpha-numeric code values, the code value on both sides of the hyphen must be the same number of characters. (For example, WinCross can correctly evaluate SEGMENT (A-D) or SEGMENT (AA-DD) but CANNOT correctly evaluate SEGMENT (A-DD) or SEGMENT (AA-D)). Care should be taken to check table results when using the range of values in logic where the code values are alpha-numeric.

Nonconsecutive values are separated by commas:

Example 1:

3/23:2(3,13-20,23)

represents “record 3, positions 23 and 24 (represented by the field width 2), value of 3 OR 13 OR 14 OR 15 OR 16 OR 17 OR 18 OR 19 OR 20 OR 23.”

Example 2:

INCOME(2,7)

represents “variable INCOME, value of 2 OR 7.”

Example 3:

Q1( ,9)

represents “variable Q1, value of blank OR 9.”

Blanks Indicated by Spaces

Example:

5:2( )

represents, “record 1 (this is implied when there is no / separating the record number from the position), positions 5 and 6 (field width 2), a blank value.” Use a space in parentheses when testing a blank value. Only one space is required for fields having multiple positions.

Offset Mode

When working with ASCII, you can specify logic without specifying the record each time. You can use “record image” or “offset mode”. For example, the record image: 1/20 can be represented as: 20.

This notation, also referred to as “position orientation,” can be quite useful for data files having multiple records per case. If you have two records, each with 80 positions and you want to refer to the second record, tenth position, the record image would be: 2/10 (1). Its offset mode would be: 90 (1).

You know the offset notation refers to record 2 by subtracting 80 (the possible number of positions per record) from the total (90); therefore 90 (1) must refer to the 10th position of record 2—the equivalent of 2/10 (1).

When writing glossary variables, you can use the offset mode only with DEFINE statements and IF conditions.

Braces

Braces { } are used to indicate which expressions should be evaluated together and the order in which they should be considered. Expressions become “nested” within statements, so this is called “nested logic.” One set of braces can appear within another and you can use an unlimited number of brace pairs within a statement. There must be an equal number of left and right braces within any single statement; any statement with a missing brace will not pass the syntax check when you run tables.

Related topics:

Logic examples

Logic Structure

Reserved Key Words