1. Home
  2. SETCALCULATE directive

SETCALCULATE directive

Performs Boolean set calculations on the contents of vectors or pointers.

Options

NULL = scalar Returns either 1 or 0 according to whether or not the result is a null (i.e. empty) set
FREPRESENTATION = string token How to represent factors in a calculation that contains only factors (levels, labels); default leve
TOLERANCE = scalar Tolerance to use when comparing numerical values; default 10-6
SUBSTITUTE = string token Whether to substitute dummies within pointers in the expression (yes, no); default no
NOMESSAGE = string tokens Which warning messages to suppress (novalues); default * i.e. none

Parameter

    expression Expression defining the calculation to be performed

Description

The SETCALCULATE directive allows you to perform set operations. The calculation must have a single assignment, setting a pointer, variate, text or factor to the result of a set calculation involving other compatible structures. Calculations on pointers must involve only pointers, those on variates and those on texts can involve factors, while those on factors can involve either variates or texts but not both.

For example, you can form a variate All that contains all the distinct values that occur in either of a pair of variates x and y using the .OR. operator

SETCALCULATE all = x .OR. y

or all the (distinct) values that occur in both of them using the .AND. operatorSETCALCULATE both = x .AND. y

The available operators are as follows:

    .OR. represents the Boolean “or” operation: for example x.OR.y produces a vector that contains any item that is in either x or y
    .AND. represents the Boolean “and” operation: for example x.AND.y produces a vector that contains any item that is in both x and y
    .EOR. represents “either or”: for example x.EOR.y produces a vector that contains any item that is in either x or y but not both of them
    - represent “not”, for example x-y produces a vectors that contains the items that are in x but not in y
    + synonym of .OR.
    , synonym of .OR.
    * synonym of .AND.

The NULL option can save a scalar whose value is 1 if the calculation generates an null set (i.e. one that has no members); otherwise the scalar is set to 0. The FREPRESENTATION option determines whether the values of factors are compared using their levels or their labels; by default the levels are used. The TOLERANCE option defines the tolerance to be used when comparing numbers. The default value 10-6 should be suitable, however, unless the variates contain very small values. If the calculation is operating on pointers, the SUBSTITUTE option controls whether or not to replace any dummies that they contain by the structures to which they point. Finally, the NOMESSAGES option allows you to suppress the warning message that SETCALCULATE produces if one of the data structures in the calculation has no values.

Options: NULL, FREPRESENTATION, TOLERANCE, SUBSTITUTE, NOMESSAGES.

Parameter: unnamed.

Action with RESTRICT

SETCALCULATE ignores any restrictions on vectors in the expression.

See also

Directives: SETALLOCATIONS, SETRELATE, SET2FORMULA, CALCULATE.

Procedure: FDISTINCTFACTORS.

Commands for: Calculations and manipulation.

Example

" Examples 1:4.3.2 and 1:4.3.3 "
" Examinations passed by three students "
TEXT Jim,Kim,Tim; VALUES=\
     !t(Art,English,French,Geography,History,\
        'Information technology',Maths,Music,Science,Spanish),\
     !t('Business studies',English,French,Geography,History,\
        Maths,Music,'Resistant materials',Science,Spanish),\
     !t('Business studies',English,French,Geography,History,\
        'Resistant materials')

" Compare Jim with Kim: neither set of exams is a subset of the other"
SETRELATE Jim; Kim; CONTAINS=Kim_subset_of_Jim;\
          EQUALS=Jim_same_as_Kim; INCLUDEDIN=Jim_subset_of_Kim
PRINT     [ORIENTATION=across; RLWIDTH=20]\
          Kim_subset_of_Jim,Jim_same_as_Kim,Jim_subset_of_Kim;\
          DECIMALS=0

" but Tim's exams are a subset of Kim's."
SETRELATE Kim; Tim; CONTAINS=Tim_subset_of_Kim;\
          EQUALS=Kim_same_as_Tim; INCLUDEDIN=Kim_subset_of_Tim
PRINT     [ORIENTATION=across; RLWIDTH=20]\
          Tim_subset_of_Kim,Kim_same_as_Tim,Kim_subset_of_Tim;\
          DECIMALS=0

" All exams passed by any of the students "
SETCALCULATE All_exams = Jim .OR. Kim .OR. Tim
PRINT        All_exams; JUSTIFICATION=left

" Exams passed by both Jim and Kim "
SETCALCULATE Jim_and_Kim = Jim .AND. Tim
PRINT        Jim_and_Kim; JUSTIFICATION=left

" Exams passed by Kim but not Tim "
SETCALCULATE Kim_not_Tim = Kim - Tim
PRINT        Kim_not_Tim; JUSTIFICATION=left

" Exams passed by only one student "
SETCALCULATE One_student = (Jim - (Kim .OR. Tim))\
                      .OR. (Kim - (Jim .OR. Tim))\
                      .OR. (Tim - (Jim .OR. Kim))
PRINT        One_student; JUSTIFICATION=left
Updated on June 18, 2019

Was this article helpful?