Have an idea?

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

Perl / SSI Function to Count

Is there a SSI script or perl function to count the 1's or 2's in a single select grid question? For example:
I've a 10 point scale(ranging from 1=Very bad to 10=Very Good) grid question with 60 statements being shown based on a constructed list. I want to know that a particular respondent has selected how many "1=Very Bad" for that question.

asked Jul 31, 2016 by Niks Bronze (620 points)
retagged Sep 1, 2016 by Walter Williams

1 Answer

0 votes
Please try this code:

[% Begin Unverified Perl
my $count = 0;
for (my $i = 1; $i <= 10; $i++) {
    if (GETVALUE('GridQ_r'.$i) == 1) {
return $count;
End Unverified %]

"GridQ" should be replaced with the grid question's name.  "10" in line 3 should be replaced with the number of rows.  "1" in line 4 should be replaced with the column you want the count for.
answered Jul 31, 2016 by Zachary Platinum Sawtooth Software, Inc. (206,100 points)
Ya. Thanks for that. I was wondering if there was a function which takes "question number" and "value to be counted" as arguments and returns the count. Something like:

The closest thing that comes to mind are NumChecked and AIC, but I don't think either could work here.
Zachary has provided you with one neat method.

Assuming your question is Q1, you can use AIE(Q1,1) for example in a constructed list (call it Q1ConList) and then use ListLength(Q1ConList) in skips or other scripting.

You can also use the SetValue function and store the count in a variable defined in the pass-in fields.

Plenty of options!