Desktop User Guides > Professional > Interview scripting > Writing interview scripts > Working with sample records > Using sample data in interviews
 
Using sample data in interviews
In ongoing or panel studies you have the chance to build up profiles of your respondents. If this profiling information is held in the sample (participant) records you can use it in the interview, either as a basis for routing or as predefined answers to certain questions in the script. For example, in a car survey that asks different sets of questions depending on the type of car owned, if the sample records contain information about the respondent’s car, you can use this information directly in the routing rather than writing an intermediate question that asks what type of car the respondent owns. Similarly, you can save time by automatically populating standard demographic questions for use in analyses by reading the answers directly from the sample records.
To access any data in the sample record, place statements of the following form in the routing section of the script:
<question> = IOM.SampleRecord.Item["<name>"]
<question> is a reference to the question or other item that is to store the sample data. The syntax for this parameter varies according to how you will be using the sample data.
Use similar names for the question and its related field in the sample record, to ensure that you load the sample data into the right questions. If your script has sample quotas, you might want to use identical names for questions and sample fields. For more information, see Sample quotas when you have No Access to the sample database.
<name> is the name of the sample field that stores the information you want to use.
Examples
For example, suppose the <name> field in the sample record contains the respondent’s name, and you want to display it as part of a personalized introductory text. First, define the welcome message in the metadata section using a named insert to mark the point at which the respondent’s name will appear:
Welcome "Hello
  {Name}. Welcome to our annual readership survey." info;
Then, in the routing section, copy the respondent’s name into the insert and display the message:
Welcome.Label.Inserts["Name"].Text = IOM.SampleRecord.Item["SampleName"]
Welcome.Show()
If you want to use the sample data as the answers to questions, you must have an appropriate question in which to put the data. For example, if the SampleAge field in the sample record contains the respondent’s age, you need a numeric question in the script to receive this information. The question is defined as:
Age "How old are you?" long [18..99];
The statements in the routing section are:
Age.Response.Value = IOM.SampleRecord.Item["SampleAge"]
This code snippet works if the age in every sample record is within the 18 to 99 range, and there are no blank ages. The interviewing program checks that the value it is importing from the sample field is valid for the question that will store it and, if not, terminates the interview with an internal program message because it does not know what to do. If you suspect that there could be invalid ages in the sample data, write your script to deal with them. There are various ways of doing this.
One way is to load the data into a temporary variable for checking before assigning it to a question, as shown in the following example:
Age.MustAnswer=False Dim checkage checkage = IOM.SampleRecord.Item["SampleAge"]
If checkage=Null Or checkage < 18 Or checkage > 99 Then
  Age.Response.Value = Null
Else
  Age.Response.Value = checkage
End If
In this example, the MustAnswer property has been set to False to allow Age to be set to null if SampleAge is blank or invalid.
Another option is to ignore the error, so that anything other than a number in the range 18 to 99 yields a null value in Age.
On Error Resume Next
Age.Response.Value = IOM.SampleRecord.Item["SampleAge"]
On Error GoTo 0
In this code snippet, the first line switches on error handling and tells the interviewing program to continue with the next statement in the script whenever it encounters an error. The second line reads in the sample value. If SampleAge is a number in the range 18 to 99 it is assigned as the response to Age, otherwise Age remains blank and the error message is suppressed. The third line switches off error handling.
This method is the simplest because you do not have to hard-code the validation values in the routing script, so changing the range in the question definition requires no further changes to the routing script. Also, there is no need to set MustAnswer to False to cater for blank or invalid values.
See also
Working with sample records