|
Not seen data like this before:
Q2 values are stored as a
string [sic]:
1;2;3;4;5;6;7;8
1;2;3;4;5;6;7;8 Hairy syntax (not mine) generates
vars:
string #temp(a22).
compute #temp=Q2. vector Q2ind=q2IND1 TO q2IND9. *vector q2ind(9,f2.0). *DO IF (MISSING(q2) EQ 0). loop #j=1 to 9. compute Q2ind(#j)=0 . end loop. loop if index(#temp,";")>0. compute #ind=index(#temp,";"). compute #j=number(substr(#temp,1,#ind-1),F2.0). * DO IF (1 LE #J AND #J LE 9). compute Q2ind(#j)=1. compute #temp=substr(#TEMP,#ind+1). * END IF. end loop. compute #j=number(#temp,F2.0). DO IF (1 LE #J AND #J LE 9). compute Q2ind(#j)=1. END IF. *END IF. EXECUTE . Same result as if Q2 responses had been coded separately in the first place
(eg q2m1, q2m2 etc.) which would have beem simpler, easier and cheaper.
This was repeated for other questions. Why don't people seek (the
best, not necessarily local) advice before they get stuck in on their
own?
|
|
On the other hand, keeping a set of values like this is a compact representation that can easily be turned into separate variables like this. -- generate a little data --- data list free /s(a20). begin data 1;2;3;4;5;6;7;8 1;2;3;4;5;6;7;8 end data. Now use the SPSSINC TRANS extension command with a tiny Python function to generate 8 string variables of length 1. The begin program block defines a small function for splitting the string. Then the spssinc trans command is used to invoke that function and generate s1...s8 as 1-byte string variables. begin program. def split(s): return s.split(";") end program. spssinc trans result=s1 s2 s3 s4 s5 s6 s7 s8 type=1 /formula "split(s)". The extension command requires at least Statistics Version 17 and the Python programmability plugin. It can be downloaded from SPSS Developer Central (www.spss.com/devcentral). Regards, Jon Peck Jon Peck SPSS, an IBM Company [hidden email] 312-651-3435
Not seen data like this before: Q2 values are stored as a string [sic]: 1;2;3;4;5;6;7;8 1;2;3;4;5;6;7;8 Hairy syntax (not mine) generates vars: string #temp(a22). compute #temp=Q2. vector Q2ind=q2IND1 TO q2IND9. *vector q2ind(9,f2.0). *DO IF (MISSING(q2) EQ 0). loop #j=1 to 9. compute Q2ind(#j)=0 . end loop. loop if index(#temp,";")>0. compute #ind=index(#temp,";"). compute #j=number(substr(#temp,1,#ind-1),F2.0). * DO IF (1 LE #J AND #J LE 9). compute Q2ind(#j)=1. compute #temp=substr(#TEMP,#ind+1). * END IF. end loop. compute #j=number(#temp,F2.0). DO IF (1 LE #J AND #J LE 9). compute Q2ind(#j)=1. END IF. *END IF. EXECUTE . Same result as if Q2 responses had been coded separately in the first place (eg q2m1, q2m2 etc.) which would have beem simpler, easier and cheaper. This was repeated for other questions. Why don't people seek (the best, not necessarily local) advice before they get stuck in on their own? |
| Free forum by Nabble | Edit this page |
