Data editing > Changing the contents of a variable > Assignment statements > Partial column replacement
 
Partial column replacement
Quick reference
To replace a code or set of codes in one data variable with a code or set of codes in a second data variable, type:
variable1'codes1'=variable2'codes2'
codes1 and codes2 must contain the same number of codes, and the codes must be in superimposable order (for example, ‘123’ and ‘456’, but not ‘123’ and ‘135’).
Assignment statements are also used to replace parts of one column with those of another, leaving the remaining contents of that column intact. This is the only time that assignment does not overwrite everything in the recipient variable. For example, you might have:
----+----3 ... ----+----6
3 6
/ /
7 8
and you want column 124 to contain a ‘1’ only if column 159 contains a ‘7’. Write:
c124'1'=c159'7'
The result is:
----+----3 ... ----+----6
1 6
3 /
/ 8
7
However, if you write:
c124'3'=c159'3'
meaning that c124 should only contain a ‘3’ if c159 contains a ‘3’, the result is:
----+----3 ... ----+----6
4 6
/ /
7 8
The ‘3’ in c124 has been deleted because there is no ‘3’ in c159. Both examples could also be written using if, else, emit and delete, but an assignment statement is much more efficient when you have a set of codes to check for.
For more information about if, see Statements of condition: if.
For more information about else, see Statements of condition: else.
For more information about emit, see Adding codes into a column.
For more information about delete, see Deleting codes from a column.
For example, if you type:
c10'123'=c11'456'
and the data is:
+----1----+
14
35
4
the result is:
+----1----+
14
25
4
Column 10 contains a ‘1’ and a ‘2’ because c11 contains a ‘4’ and a ‘5’. The ‘3’ that was originally there has been removed because there was no ‘6’ in c11. The ‘4’ in column 10 remains untouched because it has no corresponding code in c11.
Partial assignment need not have different column numbers either side of the equals sign. Quantum accepts statements of the form:
c127'0/3' = c127'1/4'
which can be used for recoding incorrectly coded data. This example recodes a ‘0’ in column 127 as a ‘1’, a ‘1’ in column 127 as a ‘2’, and so on.
When entering codes with this type of statement, make sure that there are the same number of codes on either side of the equals sign and that they are in the same relative positions in the order &‑0123456789. The previous example used ‘123’ and ‘456’; it could also have used ‘&‑1’, ‘789’ or ‘234’ instead of ‘456’, to name but a few alternatives. The important thing is that the two groups follow the same pattern: if the first set names alternate codes (for example, ‘1357’) then so must the second (for example, ‘&024’).
The following statements are valid:
c21'&–0'=c92'456'
c21'05'=c86'49'
These are not:
c56' 0'=c91'15'
c78'123'=c81'367'
The statement for columns 56 and 91 is incorrect because blank is not a valid code here; the statement for columns 78 and 81 is wrong because the codes ‘367’ cannot be superimposed on ‘123’ (either 345 or 567 would be correct).
See also
Assignment statements