How do I group answers into categories to provide a new variable in the survey.

I have a screening question which asks people to enter their postcodes. I would then like to group the answers into three zones based on the postcode they enter and then allocate a zone to the individual response. Is there a way of doing this within the survey so that I can report on the number of people in each zone? Thanks.

From what you have mentioned, this definitely sounds like an appropriate scenario for building segments. The advanced segment option should allow you to build a rule that combines responses from multiple questions:

If you have a PRO or ENTERPRISE level account, you can do this with custom scripting. We have never done the specific task you are outlining, but we have done some similar tasks so the following is an outline of our general approach to the problem.

The first step would be to create a textbox question called ZONE. Open the LOGIC tab and select the HIDE THIS QUESTION BY DEFAULT option.

Then create an ADMIN ONLY page directly after the page on which you ask for postal codes. This page will contain your custom scripts actions.

I would be concerned about using respondent-entered data to trigger actions. Unless you have very strict validation that will absolutely ensure consistent responses, the custom scripts will not work well. My thought would be to isolate the first character of the postal code (in the American post code system this would be enough to identify a general region of the country – YMMV), and use that to trigger the action.

The custom script would first use the sgapiGetValue to obtain the entered postal code, use the sgapiSubStr function to isolate the first character of the entered postal code, use an IF statement to evaluate the first character, and then use the sgapiSetValue function to enter a value for my hidden question.

For this example we will assume that the question ID for ZONE is 8, and that the question ID for your postal code question is 4. The following is a pseudo-code example of what the script would look like:

It may be possible to create one elegant custom script of nested IF statements that would evaluate all responses. Our general approach however is to create several separate action scripts – one for each possible condition. This is cruder, but it is easier to understand when you come back to them six months and try to understand what you did.

I will leave the exact placement of the hidden question and the ADMIN ONLY page as an exercise for the reader. You can learn more about custom scripting in the SurveyGizmo documentation – http://script.surveygizmo.com/help