Page 1 of 1

Value Set

Posted: February 11th, 2020, 5:11 pm
by clyde16
Hi,
I want to create a multiple choice question with dynamic values, depending on conditions compared to previous questions
when I put a single choice question it works but multiple choice it does not work!

here is what i do:

PROC OPERATOR

preproc
      valueset OPERATOR_valueset;


          if pos ("A", Q1)> 0 then
              OPERATOR_valueset.add ("khati", 1);
          endif;
    

      setvalueset (OPERATOR, OPERATOR_valueset);

Re: Value Set

Posted: February 13th, 2020, 12:05 pm
by aaronw
Typically I see users wanting to create a dynamic value set from response of a check box. However, you want to create a dynamic value set for a check box.

If your approach is only working for a single choice then the issue is probably that the length of the check box variable is set to 1. The length of a check box variable must be equal to the number of allowable response. However, this has two issues. There isn't a programmatic way to set a variable's length. Even if there was this will muck up data collection, because CSPro partly organizes its data by length.

My approach would be to create a dictionary variable that allows for the maximum number of responses. If you have less responses code the extra ones, so they can be ignored. For example, let's say your check box allows for 5 responses. The valid responses could be "ABCDE" and "UVWXZ" could be ignored.

Re: Value Set

Posted: February 25th, 2020, 2:38 am
by btri Arjun
Dear all,

I want to make a dynamic valueset form the previous multiple questions. If Q15 is the question for dynamic valueset then, If Q5 = 1 then Q15 = Cancer, If Q7 = 1 then Q15 = TB, if Q9 = 1 then Q15 = Thyroid …. I tried to make a valueset like this;

valueset diseases;
if Q5 = 1 then diseases ("Cancer”,1);
elseif Q7 = 1 then diseases ("TB",2);
elseif Q9 = 1 then diseases ("Thyroid",3);
endif;
setvalueset(Q15, diseases);
but this shows the all values even if Q5 = 2 or Q7 = 2 ……. How is it possible?

Thank you
Arjun

Re: Value Set

Posted: February 25th, 2020, 6:55 am
by josh
You need to use diseases.add("Cancer", 1) instead of diseases("Cancer", 1).

Re: Value Set

Posted: February 25th, 2020, 11:27 pm
by btri Arjun
Dear josh,

Thanks for your response, It worked. But when I return back the previous question and go forward to the Q15, than the values added each times in the field again (see screenshot). How can I avoid this problem.

Thank you.

Arjun

Re: Value Set

Posted: February 25th, 2020, 11:30 pm
by josh
To make sure it works when you go back you should put your logic in the onfocus rather than in the preproc. Also make sure that the your valueset variable is local (declared inside the proc) or if it is declared globally then remove the old values by calling valueset.clear() by before adding in the new ones.

Re: Value Set

Posted: February 26th, 2020, 1:39 am
by btri Arjun
Dear josh,

Thank for help. It worked well.
josh wrote: February 25th, 2020, 11:30 pmvalueset.clear()
Arjun