Have an idea?

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

Getting highest 3 percentages form Constant sum question

Dear Support,

I have a question " Q3" constant sum asking about percentages for 10 products and the total will be 100 % , I need to get the 3 products with the  highest  percentages to be asked in another question , how can i do this.

Please note that the list of Q3 is a constructed list from S7 question.
asked Jan 21, 2019 by Marwa

1 Answer

+1 vote
Try making a constructed list with this script:

Begin Unverified Perl
# Parameters
my $parentList = 'list1';
my $constantSumQ = 'ConstantSumQ';

# Run
my %scores = ();
for (my $i = 1; $i <= LISTLENGTH($parentList); $i++) {
    $scores{$i} = GETVALUE($constantSumQ . '_' . $i);
}
my @keys = sort { $scores{$b} <=> $scores{$a} } keys(%scores);

for (my $i = 0; $i < 3; $i++) {
    ADD($parentList, $keys[$i]);
}
End Unverified


Lines 3 and 4 must be updated with the names of the parent list and constant sum question, respectively.
answered Jan 21, 2019 by Zachary Platinum Sawtooth Software, Inc. (143,625 points)
Very nice work Zachary. I do something similar using an array and the sort function for this very same issue.
But when i did this the questions didn't appear at all .
No its working now . thank you
...