Desktop User Guides > Professional > Data management scripting > Data cleaning > Data cleaning examples > Example 4: Cleaning other question types
 
Example 4: Cleaning other question types
Special category selected with regular categories in response to a multiple response question
The special Don't Know, No Answer, and Refuse to Answer categories are generally defined as exclusive or single-choice even when they are part of a multiple response question. This example shows using the > Comparison operators to test whether the No Answer category has been selected in combination with any other response in answer to the Remember multiple response question. If it has been, the Difference function is then used to remove the No Answer category from the list of responses.
If Remember > {Not_answered} Then
  Remember = Difference(Remember, {Not_answered})
End If
You can test whether categories have been defined as exclusive using the Attributes property of the DMOM Category object. For example, the following code uses For Each...Next to loop through the categories in the question, testing whether any of them are defined as exclusive. If a category is exclusive and it has been chosen with any other responses, the code uses the Difference function to remove the exclusive category from the list of responses. The code uses the BitAnd function to test whether the caExclusive attribute has been set.
Dim myCategory
If Remember.AnswerCount() > 1 Then
   For Each myCategory in Remember.Categories
     If BitAnd(myCategory.Attributes, CategoryAttributes.caExclusive) And Remember >= myCategory Then
    Remember = Difference(Remember, myCategory.Value)
  End If
  Next
End If
Alternatively, you can use the individual response values to look up the corresponding category in the Categories collection. For example:
Dim Value, i
If Remember.AnswerCount() > 1 Then
For i = LBound(Remember.Response.Value) to UBound(Remember.Response.Value)
Value = CCategorical(Remember.Response.Value[i])
If BitAnd(Remember.Categories[Value].Attributes, CategoryAttributes.caExclusive) Then
Remember = Difference(Remember, Value)
End If
Next
End If
This example uses the LBound and UBound functions to loop through the responses, because the Response.Value property does not support the For Each loop.
When using the response to access the category in the Categories collection, you will get an error (typically “Object required when accessing Attributes”) if the response in the case data does not correspond to a category in the Categories collection or the case data contains a Null value. The first problem typically occurs when you are working with case data that was collected with multiple versions and the category that corresponds to the response in the case data has been deleted from the version being used for the transformation. You can avoid this problem by selecting all versions of the metadata for the export and using IS NOT NULL to filter out the Null values. For an example, see the CreateDRS.dms file. For more information, see Sample DMS files.
Open-ended response is too long
This example uses the Trim function to strip leading and trailing spaces from an open-ended response and then uses the Len function to return the number of characters that remain. If greater than 90, the response is set to the 90 leftmost characters that are returned by the Left function.
Dim AddressLength AddressLength = Len(address.Trim())
If AddressLength > 90 Then
  address = Left(AddressLength, 90)
End If
Accessing the open-ended responses to an Other Specify category
You can access the responses to an Other Specify category using the Response.Other property. This returns a collection of Response objects. The following example shows writing the Other Specify text to a text file.
If MyQuestion.Response.Other.Count >= 1 Then
For Each OtherResponse in MyQuestion.Response.Other
strResponse = CText(SerialNumber) + ": " + CText(OtherResponse.Value)
dmgrJob.GlobalVariables.mytextfile.WriteLine(strResponse)
Next
End If
This example is in the GetOtherSpecifyText.dms sample. For more information, see Sample DMS files.
Accessing special responses to non-categorical questions
Non-categorical questions (that is, numeric, text, date, and boolean questions) can include Don't Know, No Answer, and Refuse to Answer special responses. In a non-categorical question, special responses are defined as categories in the question's codes list and are marked as exclusive, meaning that they cannot be combined with any other answer.
You can access the responses to a question's codes list using the Response.Coded property. The following example shows how to test if the response to question Q1's codes list is a category named REF, meaning Refuse to answer:
If Q1.Response.Coded = {REF} Then
Debug.Log("Respondent: " + CText(Respondent.Serial) + _
" - Response to question Q1 is 'Refuse to answer'")
End If
Requirements
UNICOM Intelligence Professional
See
Data cleaning examples