Data editing > Changing the contents of a variable > Assignment statements > Assignment with and, or and xor
 
Assignment with and, or and xor
Quick reference
To copy codes which are present in at least one of a list of columns, type:
data_var_name=or(cnum1['codes1'], cnum2['codes2'], ...)
To copy codes which are present in all of a list of columns, type:
data_var_name=and(cnum1['codes1'], cnum2['codes2'], ...)
To copy codes which are present in only one of a list of columns, type:
data_var_name=xor(cnum1['codes1'], cnum2['codes2'], ...)
If any of these statements includes codes (p), only those codes are checked for. Any unlisted codes are then ignored.
More information
The final type of assignment is copying codes from a set of columns. The codes copied depend upon the type of operator used:
and
Copy codes present in all columns.
or
Copy codes present in one or more columns.
xor
Copy codes present in one column only.
The format of the statement is:
column = operator(ca,cb,cc, ...)
ca, cb, and cc are the columns whose codes are to be compared. Note that even if you are comparing codes in consecutive columns, each column must be identified separately, preceded by a c.
Suppose you have:
----+----4
111
/22
453
77
and you type:
c181=and(c137,c138,c139)
the result is:
----+----4 ... ---8----+
111 1
/22 2
453
77
Even though the codes ‘3’ and ‘7’ appear in more than one column, they are not copied to c181 because they are not common to all columns.
For example, take the same three columns with the or operator. Type:
c182=or(c137,c138,c139)
which gives:
----+----4 ... ---8----+
111 1
/22 /
453 5
77 7
c182 contains a list of all codes present in at least one of the named columns.
Now, look at the same columns with xor:
c183=xor(c137,c138,c139)
yields:
----+----4 ... ---8----+
111 4
/22 5
453
77
Here only two codes have been copied, because all other codes appear in more than one column. If one column was blank, this would be ignored if there were other codes unique to one column. Only if there were no other unique codes would column 183 be blank. For example, if you have c11=’ ’, c12=’12’, c13=’13’ and you type:
c14=xor(c11,c12,c13)
you would have c14=’23’, but if c13 were to contain a ‘12’ instead, c14 would be blank.
Specific codes
All the examples above refer to whole columns, but sometimes you might be interested only in specific codes in those columns. To write this in Quantum, follow each column number with the positions to be checked enclosed in single quotes. Any unnamed codes in those columns are then automatically ignored. Here is an example. The data is:
----+----4----+----5
1 1 2
/ 3 /
5 5 6
The statement c85=and(c31'1/3',c41'1/3',c45'1/3') gives:
----+----4----+----5 ... 8----+----9
1 1 2 3
/ 3 /
5 5 6
Even though column 31, 41 and 45 all contain a ‘3’ and a ‘5’, Quantum only copies the ‘3’ because the ‘5’ is not part of the specification. The example uses the same code specification for all three columns, but you can use whatever combination you like.
Note These types of statement are extremely useful for setting up shorthand references to the codes present in a group of columns. Say, for example, that you wanted various statements throughout the edit to be executed only if there was a ‘1’ in one or more of c110, c112, c120 and c125. You can always write out each column and code separately each time:
if(c110'1'.or.c112'1'.or.c120'1'.or.c125'1') .....
but it is simpler and more efficient to say:
c181=or(c110,c112,c120,c125)
if (c181'1') ...
especially if you need to refer to the contents of these columns again later in the edit. This facility can also be used to simplify what would otherwise be complicated filter conditions in the tabulation section.
See also
Assignment statements