Have an idea?

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

How to use global variables?

Hi Team,

We are capturing 4 questions with different options in each,
a score needs to given for all 4 questions based on the respondent choices.

say for example, if a respondent has car we need to give them a score of 50 if he doesn't have then score should be 10.

in 5th question we need to sum of the scores in different category, also here we need to display the scores for all 4 questions to the respondent, can you please help me to do this?

my idea is to store assign the scores to a global variables and use those scores in last question, is it possible?

asked Jun 19 by raaamuz (360 points)
I was wondering if you could provide more details on the 4 questions where the scores are collated. Are they select questions? Are they single or multiple responses? Please provide code list details and score details.

I might be able to assist here.

If this is a conjoint issue, it will best be answered by the conjoint wizards out there like Aaron Hill, Bryan Orme, Keith Chrzan, and co.
All 4 questions are select type questions, you could consider all 4 questions are  yes/no type questions, any other details you require?
Are you allocating Yes=50 points and No=10 points for each of the 4 questions?

Example ...
If Q1=Yes (50)
If Q2=No (10)
If Q3=Yes (50)
If Q4=Yes (50)

So you want the total in this example of 160 to appear at Q5?

Yes, this is what I want, any possibilities of applying this?
Leave this with me.

I will create a TotalScore variable behind the scenes and enable you to display it at Q5.

Just one last question - Are you using v8 or v9?
I am using v9.7, thanks for your support

1 Answer

+1 vote
Here we go with the solution ...

Click on the Access key and select the Pass-In Fields tab.

Now define a variable called "TotalScore" and set it as a whole number. Save that.

I have assumed you have setup Q1, Q2, Q3 and Q4 as select questions with responses of 1=Yes and 2=No.

Insert this script into a question footer after Q1+Q2+Q3+Q4 have been answered.
[%Begin Unverified Perl

 my $i=1;
 my $ts=0;

 for ($i=1; $i<=4; $i++)
   if (VALUE("Q".$i)==1)


End Unverified%]

To display the total score at a future question, display this in your script ...

I can send you a working ssi file example if you like.

Send your email through if you like that option.
answered Jun 19 by Paul Moon Platinum (75,380 points)
edited Jun 19 by Paul Moon
Thanks, before share the sample please confirm, do I need to create 4 pass-in variables if I need to display all the scores in Q5?

As I mentioned earlier, I need to display the scores they have scored in all 4 questions to the respondent in Q5. Nowhere i could see the syntax for that.

you can share the example to raamamoorthy@gmail.com
Is not possible to hide the pass-in fields? "TotalScore" is being displayed on the first screen as textbox,  not able to move and not able to set pre-skip logic.

please help me to hide that field from respondent's site
In my example, I have created only one total (I called it TotalScore) based on responses mentioned at Q1-Q2-Q3-Q4.

I'll send the ssi file through to your email for you to review.

My ssi file shows you how to hide the TotalScore being calculated.
Thanks a lot
Did you receive the file okay?
Yet to check, I took reference from the above code you have shared and did the alternate for the time being, that is I have created a free-format question with 5 fields and I setvalue to all 5 fields with respect to the question and used for calculation, it is working fine.

Let me check the file you have shared and let you know. thanks for your support.
A hidden free format question will work.

You can also pop the script into a select question that uses a constructed list evaluating to only one item. That will evaluate the script and not display the question.

There's  a few alternatives to hiding the question.