Identifying segments for screening purposes

I need to identify segments in the screening section of a survey that will qualify for it. We have a 5-segment algorithm based on 5 questions + a constant. The segment is identified by multiplying the questions value ( 1 to 5) by its coefficient for each segment, adding them and selecting the segment with the largest sum. Of the 5 segments we need only those who fall in segment 1 or 2, so I need a way to:
- Calculate the multiplication between the questions' value and its correspondent coefficient by segment and store it
- Calculate each segment total sum of coefficients + constant and store it
- Select the segment with the largest sum and store its value (1 to 5)

Is there a way of doing this using SSI script functions or Perl in SSIweb?

You are talking about pulling the Fischer's discriminant function calculations into SSI Web.  You can do this by creating hidden variables in a Free Format question:  write your equations in unverfied perl inside the HTML definition for each variable.  Be sure to test your equations very carefully to make sure they function as you want them to by using the generate data feature of the software.
answered Jan 28, 2014 by Platinum (71,075 points)
Here's a free format hidden variable example  where a variable called "HdSegment1_CODE" is created and takes the Q1 response and adds 3 to it. You can perform all mathematical functions. Pop this in the HTML box ...

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

my \$segment1_code=0;

\$segment1_code=VALUE("Q1")+3;

return \$segment1_code;

End Unverified
%]
">
```

Create a number of segment variables in free format hidden variables as Keith mentioned. Once you have all variables calculating correctly, you can pop them into another free format hidden question and use conditional script to determine the highest segment value or sort them in an array using Perl.
answered Jan 28, 2014 by Platinum (72,240 points)
Thank you! What would be the code to to determine the highest segment by their estimated value using Perl?
Let's assume you have earlier calculated 5 segment variables called QS1 / QS2 / QS3 / QS4 / QS5 (as indicated in my earlier post).

In a new free format hidden question, you can sort the 5 segment values from highest to lowest by storing them in an array, sorting them in descending order and selecting the first item (that being the highest value) from the array. See code below ...

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

my @segments=(VALUE("QS1"),VALUE("QS2"),VALUE("QS3"),VALUE("QS4"),VALUE("QS5"));
my @sortedsegments=0;
my \$highestsegment=0;

@sortedsegments=sort{\$b<=>\$a}@segments;

\$highestsegment=\$sortedsegments;

return \$highestsegment;

End Unverified
%]
">
```

So the HdHighestSegment_CALC variable has the highest segment value stored.

Create the following parent list ...

1 Segment 1
2 Segment 2
3 Segment 3
4 Segment 4
5 Segment 5

And now create the following constructed list ...

```Begin Unverified Perl

if (VALUE("QS1")==VALUE("HdHighestSegment_CALC"))
{
}

if (VALUE("QS2")==VALUE("HdHighestSegment_CALC"))
{
}

if (VALUE("QS3")==VALUE("HdHighestSegment_CALC"))
{
}

if (VALUE("QS4")==VALUE("HdHighestSegment_CALC"))
{
}

if (VALUE("QS5")==VALUE("HdHighestSegment_CALC"))
{