Checkbox and SPSS

Discussions about CSEntry
Forum rules
New release: CSPro 8.0
Post Reply
Cecilius
Posts: 6
Joined: July 19th, 2016, 12:59 pm

Checkbox and SPSS

Post by Cecilius »

Hi CSProusers

When I do the survey the options appear with their corresponding checkboxes but at the moment of exporting to SPSS I always encounter the problem of placing all the selected options in a single field. Example: What are your favorite fruits
1 apple
2. Pear
3. Pineapple
4. Strawberry

We select apple, pineapple and strawberry thus: 134 as answer of the question ... in the data dictionary it is coded separately not together.
Help please, I have done several surveys and in all I have had to use Excel to separate by commas each value (answer)
Mariovaisman
Posts: 133
Joined: February 11th, 2013, 8:26 am

Re: Checkbox and SPSS

Post by Mariovaisman »

Hello Cecilius,
If I am not wrong, you are using a single variable to allow multiple answers question, like 1,2,3,4. If it is this case, CSPro export as a single variable with all the responses. There is no way to divide it during the export process. However, you can create in the dictionary single answer variables which are not included in the form. Then you can add a postproc procedure in the multiple answer question and complete the new single variables depending on the answer, for example the answer is 124, then you use the block

do varying i=1 until i > length(strip($))
if $[i,1] = "1" then
newvar1 = 1;
elseif $[1,2] = "2" then
newvar2 = 1;
elseif $[i,1] = "3" then
newvar3 = 1;
elseif $[i,1] = "4" then
newvar4 = 1;
endif;
enddo;

These variables newvar1... newvar4 will be filled and then in the export you can have each fruit in a different variable.
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Checkbox and SPSS

Post by josh »

Mario is correct in that the best approach is to convert to a series of yes/no variables. However I would use the pos() function to determine if a value is checked since it will not matter where in the field the value for that checkbox is. If you just check $[i,2] = "2" it will not be correct if item 1 was not selected since then "2" will be in the first position. Instead check if pos("1", $) > 0. See page 5 of this document for an example: http://teleyah.com/cspro/DCJune2015/04-CAPI/04-CAPI.pdf
sah
Posts: 97
Joined: May 28th, 2015, 3:16 pm

Re: Checkbox and SPSS

Post by sah »

Another option is to parse it in SPSS or use the function below:

Code: Select all

DEFINE !parse (var=!TOKENS(1) /nbval=!TOKENS(1))
COMPUTE !var=CONCAT(RTRIM(!var),';').
STRING #str(A8).
VECTOR !var (!nbval F8.0).
COMPUTE #beg=1.
LOOP #cnt=1 TO !nbval.
+COMPUTE #str=SUBSTR(!var,#beg).
+COMPUTE #end=INDEX(#str,';')-1.
+DO IF #end=-1.
+ BREAK.
+END IF.
+COMPUTE !var(#cnt)=NUMBER(SUBSTR(#str,1,#end),F8.0).
+COMPUTE #beg=#beg+#end+1.
END LOOP IF #end=-1.
EXECUTE.
!ENDDEFINE.
* Call the macro.
!parse var=c254 nbval=5.
!parse var=c256 nbval=5.
Replace the semicolons above with commas, and it should work. 
Note that nbval is the number of possible options, and this code will give warnings if fewer are selected.
Post Reply