Have an idea?

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

perl in constructed list to add option chosen in select question

I have a study with many select questions, and constructed lists all having a single parent list
I need to create an extra constructed list to display in a select question.

The first member is simple, for example the selection made in the question 'aw'.
AIC (aw)

The second member is determined by earlier responses, and I have created pass in fields (ax,bx,…fx) which are assigned 0 or 1 values based on responses to earlier questions.

The second member will be  the option selected in one of the questions: a3,  d3, e3, or f3.
Those questions have constructed lists as their response options: a3p, d3p, e3p,  f3p.
  

I am struggling with the required perl  I need in that constructed list.
Intuitively (to me) it seems like I want something like:
AIC (aw)
Begin Unverified Perl
if(VALUE("ax")=1 && VALUE("bx")=1 && VALUE ("cx")=1 ) {AIC(a3);}
if(VALUE("ax")=1 && VALUE("bx")=1 && VALUE ("dx")=1 && VALUE ("cx")=0 ) {AIC(d3);}
else  {AIC(f3);}
End Unverified


But looking at past examples it seems I need ADD (a member) rather than AIC
But  am not sure how to add the member chosen, for example add the member chosen in question a3 which has the constructed list a3p , or add the member chosen in question d3 which has the constructed list d3p

    
AIC (aw)
Begin Unverified Perl
if(VALUE("ax")=1 && VALUE("bx")=1 && VALUE ("cx")=1 ) {ADD("a3"),1;}
if(VALUE("ax")=1 && VALUE("bx")=1 && VALUE ("dx")=1 && VALUE ("cx")=0 ) {ADD("d3"),1;}
else  {ADD("f3"),1;}
End Unverified


Hope someone can help on this
, thanks
Dan
asked Jun 2, 2021 by dan r Bronze (4,025 points)
Did you mean to use "elsif"?

This is not valid Perl:

ADD("a3"),1;


Did you mean to write this?

ADD("a3", 1);
You are of course right that
ADD("a3", 1);
would be correct.

But  I am not sure that will deliver what I want to achieve which is to add the option chosen, something like:
{AIC("a3");}
or
{AIC("d3");}
depending on the values of ax, bx etc

Dan

1 Answer

0 votes
At a real quick glance your main issue is you need to use == instead of =
answered Jun 2, 2021 by Jay Rutherford Gold (49,130 points)
Also all question/variable names need to have "" around them.  You missed it on your aic instruction inside of perl.
Thanks Jay, so AIC is ok to use here, doesn't need to be ADD (once I repair my == and "" errors)?
Dan
So sorry Dan, missed your question last night and have had a full plate this morning first thing.  Yes, AIC can be used inside perl script.  If you are still stuck reply back and I should be able to give it a bit more attention this time!
Thanks Jay and Zachary, I got there in the end, using ADD from a Constructed List ("thirds") to which were added items previously selected in Select questions, for example:
AIC(cw)
Begin Unverified Perl
if   (VALUE("cx")==1 && VALUE("dx")==1 && (VALUE("ax")==1 or VALUE("bx")==1)){ADD("thirds",4);}
elsif(VALUE("ax")==1 && VALUE("bx")==1 && VALUE("fx")==1 )                   {ADD("thirds",6);}
elsif(VALUE("ax")==1 && VALUE("dx")==1 && VALUE("ex")==1  && VALUE("fx")==1) {ADD("thirds",6);}
elsif(VALUE("ax")==1 && VALUE("cx")==1 && VALUE("ex")==1  && VALUE("fx")==1) {ADD("thirds",6);}
else {ADD("thirds",5);}
End Unverified
Glad you got it working as you wanted.  I will remind/caution you about building a constructed list from another constructed list.  When you have {ADD("thirds",4);}, since 'thirds' you indicated is a constructed list, it will add the 4th member of the constructed list (not the parent list) so that item could be different each time.  If you intended to always add item 4 from the original parent list then you would want to reference the parent list and not the constructed list.

If you were already cognizant of that, then you should be all set.  Great job!
Thanks Jay
I do want to add items according to their position in "thirds" not the parent list - this is just an (inelegant) means to add a selected item (before I realised I could just AIC rather than ADD!):

" thirds" is of the form:
AIC(a3)
AIC(b3)
AIC(c3)
AIC(d3)
AIC(e3)
AIC(f3)

and those questions are all compulsory, so they are always added, eg f3 is always the 6th item.

Dan
...