Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

is there a quick way of terminating respondents based on their zip codes?

The respondents first will be asked to enter their (5 digit) zip codes and then I need to terminate the respondents based on their responses unless they live in the 50 zip codes that I have in my list. How can I do that?
Thank you in advance!
asked Nov 5, 2011 by anonymous
retagged Sep 1, 2016 by Walter Williams

7 Answers

+2 votes
One way is to use a simple skip with a stack of ZIP codes set within the condition.

You can be more creative using a free format hidden question or a constructed list that sets a variable to "1". If the variable=1, then skip to end and terminate.

Example.

*Create a parent list called ZipFlagList with code 1 set to "True"
*Create a constructed list called ZipFlagConList that gets code 1 from ZipFlagList if the ZIP code condition is true.


Begin Unverified Perl

if (VALUE("ZIPCODE")==?)
 {
  ADD("ZipFlagListList",1);
 }

End Unverified

*Note - "?" refers to terminating ZIP codes.

You can create a skip that uses the condition IF ListLength(ZipFlagConList)=1 then skip to end and terminate.

That will work nicely and if you need to change the ZIP codes, just go in and modify the constructed list condtion(s).
answered Nov 5, 2011 by anonymous
+2 votes
You can also just return true for your skip logic or quota cell.

[% Begin Unverified Perl

my %ZipCodesHash = ();

# CODE TO LOAD ZipCodesHash with zipcodes you want to not allow

return exists $ZipcodesHash{"ZIPCODE"};

End Unverified %]
answered Nov 7, 2011 by Mike Lodder Gold (23,435 points)
edited Nov 7, 2011 by Mike Lodder
I want the repondents enter any 6 digit zipcodes and I only have a list of zipcodes that I wan to allow respondents to continue with the survey and the respondent can enter any zipcode. Since I don't have the specific list of terminating zipcodes, which way is the best?
Thank you in advance
So in this case you can simply just put the valid zipcodes in the hash and the rest of the code should not change.

[% Begin Unverified Perl

# CODE TO LOAD ZipCodesHash with zipcodes you want to not allow
#Example
my %ZipCodesHash = ( '98382' => 1,
                                         '84092' => 1); #ADD your own here

return exists $ZipcodesHash{"ZIPCODE"};

End Unverified %]
+2 votes
We always screen on zip. What we do is have an "intro" survey that asks respondents to enter their zip code. After they enter the zip, we terminate them from the "intro" survey and send them to the "main" survey with the zip code in the URL. The "main" survey has the zip codes set as passwords to enter. The zip in the URL is compared to the list of passwords and those with a valid zip enter the "main" survey and those that don't receive a message saying that they didn't qualify.

The biggest problem with this is that you will have two sets of terminated respondents... those who termed based on zip and weren't able to enter the "main" survey and those who termed within the "main" survey. You'll also have to do some de-duping on the back end to figure out which of the Completes on the "intro" survey went on to the "main" survey and which were termed based on zip (because everyone will be classified as Qualified/Complete).
answered Nov 10, 2011 by John Holmes (255 points)
+2 votes
I use the hidden value method, works great. Key is to use excel to set up the lists you need. I just split something like the below at the ...eq" paste in column of coded accepted "} {return "1";} and then paste into notepad and replace tabs with nothing. Then set skip patter to post skip if (in this case Canadian FSA < > Toronto) fsa1_a = 0. Very easy.

This is a text based version:

<input name="fsa1_a" id="fsa1_a" type="hidden" value="
[%Begin Unverified Perl
if (VALUE ("fsa_fsa") eq "M2H") {return "1";}
if (VALUE ("fsa_fsa") eq "M2J") {return "1";}
else {return "0";}
End Unverified
%]
">


Similar example to assign  a zipcode to a region, then used to set quotas by region, free format question, hidden, called zip_region:

Paste this part into the HTML

<input name="zip_region" id="zip_region" type="hidden" value="
[%Begin Unverified Perl
if (VALUE ("q3") == 6401) {return "12";}
else {return "0";}
End Unverified
%]
">


Can provide demo file if you want
answered Nov 10, 2011 by j.bratton Bronze (620 points)
+2 votes
We do this quite a lot.  I have a list of (Australian) states and territories.  I also wrote some simple perl code (concatenated using excel) to set a constructed question based on the postcode (or zip) as entered.  (so, if(VALUE("postcode") == 2000) { ADD("StateList",1); } ).

I can then quite happily run state quotas based on this of course, or merely screen out based on the length of the list (listlength(StateSet) == 0).

Seems to work ...
answered Nov 10, 2011 by Marion Bronze (3,435 points)
+2 votes
I tried to use the hidden variable method with 5000 zipcodes to classify them into regions and then use that for skips, but it only returning 0 for the hidden variable.
S3 is the question when respondents put their zip code in a numeric box. The code I used is:

<input name="zip_region" id="zip_region" type="hidden" value="
 [%Begin Unverified Perl
if (VALUE ("s3") == 43003) {return "1";}
if (VALUE ("s3") == 43006) {return "2";}
if (VALUE ("s3") == 43008) {return "3";}
if (VALUE ("s3") == 43009) {return "4";}
else {return "0";}
 End Unverified
 %]
 ">

Is there anything wrong with this code?

Thanks,
M
answered May 19, 2012 by anonymous
are you sure your numeric input is actually a number? try
if (VALUE ("s3") == "43003") {return "1";}

and see if it works, if it does, either cast to number or do string comparison
I put the values i quotes and it didn't work either. Any other ideas?
Isn't Perl case sensitive? Should "s3" be "S3"?

I program my Perl a little differently (see below) ...

<input name="zip_region" type="hidden" value="
[%
Begin Unverified Perl

 my $zip_region=0;

 if (VALUE ("S3") == 43003)
  {
   $zip_region=1;
  }

 elsif (VALUE ("S3") == 43006)
  {
   $zip_region=2;
  }

 elsif (VALUE ("S3") == 43008)
  {
   $zip_region=3;
  }

 elsif (VALUE ("S3") == 43009)
  {
   $zip_region=4;
  }

 else
  {
   $zip_region=0;
  }

return $zip_region;

End Unverified
 %]
 ">

Hope that gets you sorted.
Paul, You were right on the money. I was using s3 in the code, while the variable is named S3, so case sensitivy was the culprit. Thank you much for your help! You have made  my weekend!! BTW I like your way of coding Perl.
+1 vote
You can set up a quota with the zipcodes you want to accept in your Supervisor. Have that question in the beginning of course so they don't have to go through all of the questions to get to it. Before you load your sample add an extra zipcode row and name it what you like. Make a UDF for it if needed. Then you can use the zipcodes in it's normal place and for your quota.  This will automatically remove the person from the list either way. If you don't have a preassigned list then set up a regular quota . IF they are not on the quota list the users will be given a message that you set up  through a skip pattern or a pre-made message. It's all up to how  you set it up.
answered Feb 26, 2015 by Lei
...