Have an idea?

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

Piping lowest answer out of a rank or scale question to the next question?


I'm looking for a piece of SSI or pearl script that will pipe through the lowest value from a prior grid question. The grid question has a list of 10 items each with a value from 1-7 (for travel purpose and then frequency, where 1 is most frequent and 7 least frequent) so I want to list the response to the lowest valued item out of this list - that is the most used trip. Possibly there could be a tie (a slight chance) but I'm not sure how to handle that.

Does anyone have a good idea here??

asked Nov 20, 2017 by Jasha Bowe Bronze (1,680 points)
Jasha, what would you like to do in the event of multiple items scoring a "1"?

One suggestion is you can randomly select from that list.
Hi Paul,

In the unlikely instance of a tie (due to the nature of the question being asked which is which your most commonly used trip) I think it would be best to use the question that is lowest in rank (that is the one that appears first in the matrix. Does that make sense? The matrix itself is ordered in a type of hierarchy.

What do you think?

1 Answer

0 votes
Jasha, give this a shot ...

I have assumed your grid is Q1 and the items are saved in a parent list called Q1ItemsList.

Next, I have constructed a list which randomises your 10 items as such (call it Q1ItemsRandList):

Use this list as your rows list in your Q1 grid.

The constructed list below sorts your items from lowest score (1) to highest score (7). If any items are rated the same, the order of the items are kept as they were displayed at Q1.
Begin Unverified Perl

 my $i=1;
 my $s=1;

 for($s=1; $s<=7; $s++)
   for($i=1; $i<=10; $i++)

End Unverified

The first item in this list is the lowest rated item and the first displayed at Q1. Hope that makes sense.

You know how to get me if you have any issues. Regards.
answered Nov 20, 2017 by Paul Moon Platinum (57,015 points)
Paul this is great. From what you describe this will achieve exactly what I need. My final question (for tonight!) is do I do I insert the pear statement on every page I want the piped response from the grid? I assume that I place the first command on the page with the grid that the response will be coming from. And do I place the pearl script between two words if I want it to appear in the middle of a sentence?? oh and should the command on line one be ADD(Q1ItemsList) not ADD(Q1List)?
Yeh, change ADD(Q1List) to ADD(Q1ItemsList). That was a copy and paste error. Apologies.

To display your selected item, simply insert this into any question script ...

Note that Q1ItemsSortedList is the name of the constructed list that does the sorting routine.

So an example of this would be ...

"We noticed you selected [%ListLabel(Q1ItemsSortedList,1)%] as your most frequent blah blah blah ..."

Just another note, if you didn't mind equal ratings being randomised, that constructed list would have been as simple as ...

It's a great feature within a feature. It sorts your grid, either ascending or descending, and equal ratings are randomised. It's a beauty. But your request was to keep the order as per the display items which required some hard yards.

All good mate. Let me know how you go.

I'm stuck I can't get it to work.
Maybe I haven't explained it well.

My grid looks like this

                    7 days a week | 5 days a week | 3 days a week
Option 1 |            1               |             2               |            3
Option 2 |            1               |             2               |            3  
Option 3 |            1               |             2               |            3

This goes on for 7 columns and 11 items (Options 1 & 2, 3 etc) Each person rates each option (these are destination trips like to the shops or to work etc.) The lowest score they choose (notwithstanding a tie) is 1 (or it could be 2 if they dont go out much).

I want to return the label of the option with the lowest score across the 11 options, as this would be their most frequent trip (i.e. they take the trip 7 days a week). Where as to the ice cream shop might be once a month and score a 7. So I want to return the label of the most common trip (the label with the lowest number across all the individuals 11 options). It's pivotal to the rest of the survey so I'm trying my best (with your help Paul!) to get it right... but I cant seem to crack it.

Does that make it clearer? or am I just not coding this right?

Sorry to be such a pain!!
That makes sense Jasha.

I got it to work at my end.

Should I send you an ssi file?
That would be MAGIC!!!! You champion!!
Just sent the ssi file to your requested email. Works like a charm!