Page 1 of 1

Multiple disaggregate

Posted: April 27th, 2020, 7:48 am
by etuser
Dear Sir,

I am using Cspro 7.3 and I want to split a multiple response to discrete variables. For example, i have a multiple checkbox variable alpah variable which takes a 2 digit and 20 choices which means a maximum of 10 responses to the variable called Q001 , lets say 050912 in Q001 and now my clients wants to have 10 new variables created and response "05" on Q001_5 "09" on Q001_9 ...... is there any simple way other than "if else" for the whole variable?

thanks

Re: Multiple disaggregate

Posted: April 27th, 2020, 5:19 pm
by aaronw
Yes, you're going to have create the 10 new variables and then check whether the value exists or not. If you're doing this in data entry I would suggest not adding these new variables to the form. The logic will look similar to this:
// Process answers into Yes(1)/No(0) answers
if ischecked("A", TOILET_QUESTION) <> 0 then
   
TOILET_OPTION_1 = 1;
else
   
TOILET_OPTION_1 = 0;
endif;

Re: Multiple disaggregate

Posted: April 28th, 2020, 1:44 am
by etuser
Dear Arron,

Thank you very much, i tried your hint and re-work but still have one difficulty , since my choices are in alpha checkbox and numbers , I can write

Do varying i= 1 until i > length(strip(TOILET_QUESTION))
if ischecked(maketext("%02d",i), TOILET_QUESTION) <> 0 then
// since i already creating a new variable like TOILET_QUESTION_1, TOILET_QUESTION_2 ........ in my dictionary and
// if there are a way to write a name of a new variable based on the existing , things will be much simpler but failed to compile,
// it says TOILET_QUESTION_"i" not found
TOILET_QUESTION_"i" = 1

Endif;
Enddo;

Re: Multiple disaggregate

Posted: April 28th, 2020, 11:13 am
by aaronw
The issue you're having is referencing the correct variable. We can use maketext to create "TOILET_QUESTION_1", "TOILET_QUESTION_2", etc. However, these are strings and not dictionary symbols, so we cannot assign a value to them. You can use getsymbol to get the current procs symbol, but in this scenario the logic isn't going to be any better.

The above code snippet is for CSPro 7.4. In CSPro 7.3 replace ischecked with pos.