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.

tomq498008 answered

    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:

    xzip = sgapiGetValue (4); //where 4 is the question id for the postal code
    if sgapiSubStr(xzip,0,1)== ‘9’
    {sgapiSetValue(8, “Zone 3”)}//where 8 is the question id for your hidden ZONE question

    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 –

    Jim Wetherill answered

      Can this be done more simply using “advanced segments” in the Compare menu for reports?

      tomq498008 answered

        The Segmenting option is definitely worth looking into (particularly the Advanced Segment option):

        Dominic Sharpe answered

          What about after the survey is closed and you are in analysis stage? Can the scripting still be implemented at that point?

          Surely surveygizmo has a method more simple than this scripting option to allow grouping responses for closed ended questions. Right?

          (For example, if i wanted to contrast responses from younger women and older men, and needed to combine answers from two questions, one about gender and one about age.)

          Dominic Sharpe commented


            Question stats

            • Active
            • Views1485 times
            • Answers4 answers
            • Followers2 followers