Page 1 of 1

Dynamic ValueSet

Posted: February 20th, 2019, 8:02 am
by Yass
Hi Cspro

I want this dynamic value set that excludes selected field in an earlier field ... I read on the RANKING Post as suggested by Josh , I am able to relate.

I var1 with option
1. Coke
2. Fanta
3. Malta

I want a situation that if I select Coke then in var2 i dont see Coke rather see:

2. Fanta
3. Malta

Thanks

Re: Dynamic ValueSet

Posted: February 21st, 2019, 8:52 am
by Gregory Martin
Your best option is to iterate through each value of the value set and then add everything except for the one previously selected. I've attached an example application that you can use to test this. DRINK1 and DRINK2 share the same value set, but I dynamically create a value set, adding every value but the one selected in DRINK1.
PROC GLOBAL

array value_set_codes(100);
array string value_set_labels(100);

PROC DRINK2

preproc

    // create a value set, excluding the selection in DRINK1

    numeric value_set_counter = 1;

    do numeric ctr = minvalue(DRINK2_VS1) while ctr <= maxvalue(DRINK2_VS1)

        // don't add the selection in DRINK1
        if ctr = DRINK1 then
            next;
        endif;

        // don't add blank labels (because there is no code for this value of ctr)
        if getlabel(DRINK2_VS1, ctr) = "" then
            next;
        endif;

        // add the value
        value_set_codes(value_set_counter) = ctr;
        value_set_labels(value_set_counter) = getlabel(DRINK2_VS1, ctr);
        inc(value_set_counter);

    enddo;

    // end the value set
    value_set_codes(value_set_counter) = notappl;

    // set the dynamic value set
    setvalueset(DRINK2, value_set_codes, value_set_labels);

Re: Dynamic ValueSet

Posted: February 22nd, 2019, 5:31 am
by Manoj
Hi..

How to use in multiple response.

Thanks

Re: Dynamic ValueSet

Posted: February 22nd, 2019, 8:31 am
by Gregory Martin
The Simple CAPI example that comes with the CSPro installation shows how to create dynamic value sets from checkboxes.

Re: Dynamic ValueSet

Posted: March 5th, 2019, 4:07 am
by nav
Hi....

I have two multiple checkbox type question. how can set dynamic valueset in second question which is not selected in first question.

Thanks

Re: Dynamic ValueSet

Posted: March 8th, 2019, 8:11 am
by Gregory Martin
Because checkboxes are stored as strings, not numbers, the logic is a bit different. See the code below (and the attached application):
PROC GLOBAL

array string value_set_codes(100);
array string value_set_labels(100);

string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

PROC DRINK2

preproc

    // create a value set, excluding the selection in DRINK1

    numeric value_set_counter = 1;

    // the checkbox codes are stored using letters (A-C)
    do numeric ctr = 1 while ctr <= length(DRINK1)

        // don't add any selections marked in DRINK1
        if pos(alphabet[ctr:1], DRINK1) > 0 then
            next;
        endif;

        // add the value
        value_set_codes(value_set_counter) = alphabet[ctr:1];
        value_set_labels(value_set_counter) = getlabel(DRINK2_VS1, alphabet[ctr:1]);
        inc(value_set_counter);

    enddo;

    // end the value set
    value_set_codes(value_set_counter) = "";

    // set the dynamic value set
    setvalueset(DRINK2, value_set_codes, value_set_labels);

Re: Dynamic ValueSet

Posted: March 13th, 2019, 3:28 am
by nav
Thank you very much ......

Re: Dynamic ValueSet

Posted: April 8th, 2019, 11:57 am
by btri Arjun
Dear CSPro team,

There are 10 choice with label “Yes=1”, ‘No=2” and “Don’t know=8” ie
Q201.
1. Health worker
2. Friend
3. Radio
4. TV ….
Now, there is second question, Q202. Which are most credible for you? (Up to two multiple choice).
Now I want to display the all “Yes” options form the Q201. If the respondent answered 1,3, and 4 “Yes”, I want to display those 3 options in the Q202 field. What is the way out?

Best,
Arjun

Re: Dynamic ValueSet

Posted: April 8th, 2019, 2:18 pm
by josh
Make Q201 a repeating item with 10 occurrences. Use occurrence labels in your dictionary to add the option names (health worker, friend,...) to the occurrences. When you drag Q201 you will get a little roster with the rows labeled for the option names. To create the value set for Q202 you loop through the 10 occurrences and check if the occurrence value is 2 you add the code (row number) and the occurrence label (option name) to the value set. Something like this:

do numeric i = 1 while i <= 10
    if Q201(i) = 2 then
        // Chose yes, add to value set
        codes(nextEntryValueSet) = i;
        labels(nextEntryValueSet) = getocclabel(Q201(i));
        nextEntryValueSet = nextEntryValueSet + 1;
    endif;
enddo;

setvalueset(Q202, codes, labels);


You probably will also want to handle the case where they don't pick yes for any of the options in which case you may skip Q202 or force them to pick at least one option.