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
Dynamic ValueSet
-
- Posts: 1801
- Joined: December 5th, 2011, 11:27 pm
- Location: Washington, DC
Re: Dynamic ValueSet
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);
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);
- Attachments
-
- value-set-exclude-previous-selection.zip
- (3.02 KiB) Downloaded 350 times
Re: Dynamic ValueSet
Hi..
How to use in multiple response.
Thanks
How to use in multiple response.
Thanks
-
- Posts: 1801
- Joined: December 5th, 2011, 11:27 pm
- Location: Washington, DC
Re: Dynamic ValueSet
The Simple CAPI example that comes with the CSPro installation shows how to create dynamic value sets from checkboxes.
Re: Dynamic ValueSet
Hi....
I have two multiple checkbox type question. how can set dynamic valueset in second question which is not selected in first question.
Thanks
I have two multiple checkbox type question. how can set dynamic valueset in second question which is not selected in first question.
Thanks
-
- Posts: 1801
- Joined: December 5th, 2011, 11:27 pm
- Location: Washington, DC
Re: Dynamic ValueSet
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);
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);
- Attachments
-
- value-set-exclude-previous-checkbox-selection.zip
- (3.24 KiB) Downloaded 373 times
-
- Posts: 37
- Joined: August 17th, 2018, 6:09 am
Re: Dynamic ValueSet
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
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
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:
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.
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);
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.