Data editing > Changing the contents of a variable > Forcing single-coded answers
 
Forcing single-coded answers
Quick reference
To force single-coding of multicoded columns, type:
priority cn'code1', 'code2' ,'code3',[cn2'code1a', 'code2a' ,'code3a', ... ]
Codes at the start of the list are accepted in preference to any later in the list.
More information
Sometimes when you are cleaning your data, you will find a column which is multicoded when it ought to contain only one code. You can either print out the record and change the incorrect codes later or you can have Quantum do it for you automatically. When data is to be corrected automatically, you must write a statement saying which codes should be discarded and which are to be kept. Obviously, there can be no hard and fast rule since the codes can vary between questionnaires, so you can assign each code a priority so that when a certain code is found Quantum knows that all others in that column are to be deleted.
The statement used for this is:
priority cn'code1', 'code2', ...'coden',[cn2'code1a', 'code2a' ,'code3a', ... ]
where cn is the column whose codes are to be checked and ‘code1’ to ‘coden’ are the positions to check, entered in order of priority, the most important first.
Note priority checks only the listed positions; if any other codes are present they are ignored.
For example, suppose one of the questions in a survey asks respondents to give their overall opinion of a product, rated on a scale of 1 (Poor) to 5 (Excellent). You have been told that if the question has accidentally been multicoded, you are to assume that the higher rating is correct and delete the lower rating from the column. You do not know beforehand exactly what multicodes there are, if any, but you know the column and the possible codes it can contain, and also that low codes should be discarded in favor of high ones. If this question is coded into column 249, you could write:
priority c249'5', '4', '3', '2', '1'
This causes Quantum to scan column 249 to see first whether it contains a ‘5’ and, if so, to delete all subsequent codes in the list. If c249 contains a ‘5’ and nothing else, obviously there will be no extra codes to delete; this does not matter. If there is no ‘5’ in c249, Quantum then checks whether it contains a ‘4’; if so, any other codes in the range ‘1/3’ are deleted, otherwise the program skips to the next code in the list and checks for that. If none of the listed codes are found, the column remains unchanged.
If the first record has c249’53’ Quantum gives c249=’5’, but if the second has c249’942’, you get with c249’94’; the ‘9’ has not been removed because it was not one of the named positions.
You can also use priority to force a field to be single-coded by listing the columns and codes to be checked in order of importance. If a listed code is found in the first column, any other listed codes will be removed from that column, as will any that appear in subsequent columns. For example, if a record is:
-----+----6
22
3
5
and you write:
priority c55'2', '3', '4', c56'1', '2', '3', '4', '5'
the result is:
-----+----6
2
However:
-----+----6
22
3
&
becomes:
-----+----6
2&
In the previous example, there are two different columns on the same priority statement because together they form a field which must be single coded overall. If you want to force two completely separate columns to be single-coded, you must write two priority statements, one for each column. If the data is:
+----3----+
21
33
6
the statement
priority c129'1','2','3',c130'1','2','3'
gives:
+----3----+
26
but:
priority c129'1', '2', '3'
priority c130'1', '2', '3'
results in:
+----3----+
21
6
See also
Changing the contents of a variable