Gene,
yes, your syntax runs with this ‘1’ as a String, builds a new variable combo – but it remains empty. Looking for frequencies of combo, I got this
combo instead of a combo with the combinations of the number of the funkt-variable: funkt1 funkt2 funkt3 funkt4 funkt5 funkt6 funkt7 combo combodesired 1 1 0 0 0 0 0 11 12 0 0 0 0 0 1 0 1 6 1 1 0 0 0 0 0 11 12 0 0 1 0 0 0 1 11 37 1 1 0 0 0 0 1 111 127 Tom Von: SPSSX(r) Discussion [mailto:[hidden email]]
Im Auftrag von Maguin, Eugene Thomas, My apologies. This line
+ if (x(#i) eq 1) substr(combo,#j,1)=1. Should be + if (x(#i) eq 1) substr(combo,#j,1)=’1’. Gene Maguin Von: SPSSX(r) Discussion
[hidden email]
Im Auftrag von Maguin, Eugene Certainly a loop structure. Vector x=funkt1 to funkt7/y=newvar1 to newvar3. Compute #j=1. Loop #i=1 to 7. + if (x(#i) eq 1) y(#j)=#i. + if (x(#i) eq 1) #j=#j+1. End loop. What is this part about ‘…one categorical variable, which contains the most frequent combinations…’? Don’t you then want a variable like ‘combo’ with values of
funkt1 funkt2 funkt3 funkt4 … newvar1 newvar2 newvar3 combo 1 0 0 1 1 4 14 0 1 1 1 2 3 4 234 0 0 0 1 4 4 So would newvar1 to new3 are just be intermediates? If so, then why not this? Vector x=funkt1 to funkt7. String combo(a3). Compute #j=1. Loop #i=1 to 7. + if (x(#i) eq 1) substr(combo,#j,1)=1. + if (x(#i) eq 1) #j=#j+1. End loop. Gene Maguin |
With the Syntax from Kenneth McCabe I figured out another solution – which works „almost“: ****Syntax from Kenneth McCabe. DO REPEAT d = Funktion1 to Funktion7 / #i = 1 to 7. - IF d d = #i. END REPEAT. EXECUTE. ****Then the concatenation. string combo1 (A7). execute. compute combo1 = concat (STRING(Funktion1,N1), STRING(Funktion2, N1), STRING(Funktion3, N1), STRING(Funktion4, N1), STRING(Funktion5, N1), STRING(Funktion6, N1), STRING(Funktion7, N1)). execute. That works so far, but now I’d like to remove all these zeros in the strings of combo1: combo1 1 2 0 0 0 0 0 1200000 0 0 0 0 0 6 0 0000060 1 2 0 0 0 0 0 1200000 0 0 3 0 0 0 7 0030007 1 2 0 0 0 0 0 1200000 0 2 0 0 0 0 0 0200000 1 2 0 0 0 0 0 1200000 0 0 0 0 0 0 7 0000007 |
In reply to this post by Tom
Thomas, Tested this time. data list list / funkt1 funkt2 funkt3 funkt4 funkt5 funkt6 funkt7. begin data 1 1 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 0 0 0 1 end data. Vector x=funkt1 to funkt7. String combo(a3). Compute #j=1. Loop #i=1 to 7. + if (x(#i) eq 1) substr(combo,#j,1)=string(#i,f1.0). /** change here. + if (x(#i) eq 1) #j=#j+1. End loop. list funkt1 to funkt7 combo. funkt1 funkt2 funkt3 funkt4 funkt5 funkt6 funkt7 combo 1 1 0 0 0 0 0 12 0 0 0 0 0 1 0 6 1 1 0 0 0 0 0 12 0 0 1 0 0 0 1 37 1 1 0 0 0 0 1 127 Number of cases read: 5 Number of cases listed: 5 |
Administrator
|
In reply to this post by Tom
Perhaps you missed my posting from the 22nd ;-)
http://spssx-discussion.1045642.n5.nabble.com/Multiple-Responses-to-Categories-td5713754.html#a5713759
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
Thanks everybody,
both, the solution of David (yes, I missed it ;-)) and the one of Gene work very well! Tom -----Ursprüngliche Nachricht----- Von: SPSSX(r) Discussion [mailto:[hidden email]] Im Auftrag von David Marso Gesendet: Dienstag, 26. Juni 2012 16:03 An: [hidden email] Betreff: Re: AW: Multiple Responses to Categories Perhaps you missed my posting from the 22nd ;-) http://spssx-discussion.1045642.n5.nabble.com/Multiple-Responses-to-Categories-td5713754.html#a5713759 -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/AW-Multiple-Responses-to-Categories-tp5713788p5713794.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
In reply to this post by Maguin, Eugene
Hi Gene,
Thanks for your post. It seems to work with 7 functions/variables, but I was testing it with 40 and I got weird outputs ...like: 37*. Any suggestions on how to improve the script using more than 7 variables? Lets say 100. Many Thanks!
mils
|
Administrator
|
Please post *EXACT* syntax you are using, sample input, output of what results *AND* what you believe the output should be. If you are attempting to store 'concatenated' list of MANY choices in a *NUMERIC* field you may wish to back your way out of the rabbit hole and take the red pill vs the blue one.
ie Perhaps a STRING variable will be more appropriate. OTOH, meaningful interpretation of the resulting long string might cause you to go blond. What is it that you really wish to achieve from this exercise? ---
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
Hi Gene / David,
Sorry for that. Please, below you can find the data and syntax I was using: data list list /x1 to x13 . begin data 0 1 0 0 1 0 1 0 1 0 0 0 0 0 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 1 1 0 1 0 1 0 1 0 1 0 0 1 0 0 0 0 0 0 1 0 1 0 1 0 1 1 0 1 0 1 1 0 0 1 1 0 1 0 0 0 0 1 0 0 1 0 0 0 0 1 0 1 1 0 1 0 1 0 1 0 1 0 0 1 0 0 0 0 0 0 1 0 1 0 1 0 1 1 0 1 0 1 1 0 0 1 1 0 1 0 0 0 0 1 0 0 1 0 0 0 0 1 0 1 1 0 1 0 0 1 0 0 1 0 1 0 1 1 0 1 0 1 0 1 0 1 0 0 1 0 0 0 0 0 0 1 0 1 0 1 0 1 1 0 1 0 1 1 0 0 1 1 0 1 0 0 0 0 1 0 1 0 0 1 1 0 1 0 0 0 0 1 0 0 1 0 0 0 0 1 0 1 1 0 1 0 1 0 1 0 1 0 0 1 0 0 0 0 0 0 1 0 1 0 1 0 1 1 0 1 0 1 1 0 0 1 1 0 1 0 0 0 0 1 0 0 1 0 0 0 0 1 0 1 1 0 1 0 end data. fre x1 to x13. *************David********************. COMPUTE ##=1. COMPUTE COMB=0. VECTOR X=X1 TO X13 / New(13). LOOP #=1 TO 13. + DO IF X(#)=1. + COMPUTE New(##)=#. + COMPUTE Comb=Comb*10+#. + COMPUTE ##=##+1. + END IF. END LOOP. EXE. FORMATS ALL (F3.0). list. fre comb. ****Output**** 1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 COMB New1 New2 New3 New4 New5 New6 New7 New8 New9 New10 New11 New12 New13 0 1 0 0 1 0 1 0 1 0 0 0 0 *** 2 5 7 9 . . . . . . . . . 0 0 1 0 0 1 0 1 0 1 0 0 1 *** 3 6 8 10 13 . . . . . . . . 0 1 0 0 1 0 1 0 1 1 0 1 0 *** 2 5 7 9 10 12 . . . . . . . 1 0 1 0 1 0 0 1 0 0 0 0 0 *** 1 3 5 8 . . . . . . . . . 0 1 0 1 0 1 0 1 1 0 1 0 1 *** 2 4 6 8 9 11 13 . . . . . . 1 0 0 1 1 0 1 0 0 0 0 1 0 *** 1 4 5 7 12 . . . . . . . . 0 1 0 0 0 0 1 0 1 1 0 1 0 *** 2 7 9 10 12 . . . . . . . . 1 0 1 0 1 0 0 1 0 0 0 0 0 *** 1 3 5 8 . . . . . . . . . 0 1 0 1 0 1 0 1 1 0 1 0 1 *** 2 4 6 8 9 11 13 . . . . . . 1 0 0 1 1 0 1 0 0 0 0 1 0 *** 1 4 5 7 12 . . . . . . . . 0 1 0 0 0 0 1 0 1 1 0 1 0 *** 2 7 9 10 12 . . . . . . . . 0 1 0 0 1 0 1 0 1 1 0 1 0 *** 2 5 7 9 10 12 . . . . . . . 1 0 1 0 1 0 0 1 0 0 0 0 0 *** 1 3 5 8 . . . . . . . . . 0 1 0 1 0 1 0 1 1 0 1 0 1 *** 2 4 6 8 9 11 13 . . . . . . 1 0 0 1 1 0 1 0 0 0 0 1 0 *** 1 4 5 7 12 . . . . . . . . 1 0 0 1 1 0 1 0 0 0 0 1 0 *** 1 4 5 7 12 . . . . . . . . 0 1 0 0 0 0 1 0 1 1 0 1 0 *** 2 7 9 10 12 . . . . . . . . 1 0 1 0 1 0 0 1 0 0 0 0 0 *** 1 3 5 8 . . . . . . . . . 0 1 0 1 0 1 0 1 1 0 1 0 1 *** 2 4 6 8 9 11 13 . . . . . . 1 0 0 1 1 0 1 0 0 0 0 1 0 *** 1 4 5 7 12 . . . . . . . . 0 1 0 0 0 0 1 0 1 1 0 1 0 *** 2 7 9 10 12 . . . . . . . . Number of cases read: 21 Number of cases listed: 21 *************Gene********************. Vector x=X1 TO X13/y=newvar1 to newvar13. Compute #j=1. Loop #i=1 to 13. + if (x(#i) eq 1) y(#j)=#i. + if (x(#i) eq 1) #j=#j+1. End loop. Vector x=x1 to x13. String combo(a3). Compute #j=1. Loop #i=1 to 13. + if (x(#i) eq 1) substr(combo,#j,1)='1'. + if (x(#i) eq 1) #j=#j+1. End loop. fre combo. ****there is no Output**** My objective is to find out which combinations is the most frequent amog the 13 variables and I would like to test it also with 100 variables or more if it is possible. Thanks in advance. Date: Tue, 3 Jul 2012 10:33:03 -0700 From: [hidden email] To: [hidden email] Subject: Re: AW: Multiple Responses to Categories Please post *EXACT* syntax you are using, sample input, output of what results *AND* what you believe the output should be. If you are attempting to store 'concatenated' list of MANY choices in a *NUMERIC* field you may wish to back your way out of the rabbit hole and take the red pill vs the blue one. ie Perhaps a STRING variable will be more appropriate. OTOH, meaningful interpretation of the resulting long string might cause you to go blond. What is it that you really wish to achieve from this exercise? ---
If you reply to this email, your message will be added to the discussion below: http://spssx-discussion.1045642.n5.nabble.com/AW-Multiple-Responses-to-Categories-tp5713788p5713990.html
mils
|
A couple of ideas.
1. If you declare 0 (or 1) missing, do you get something useful from the Missing Values analysis of patterns? (Remember to use MISSING VALUES all (). to return to normal.) 2. If you sort on everything, then do Aggregate where you break on everything, and get the N ... then you end up with one line for each pattern, with its count. (Does Aggregate have a limit for Break variables?) -- Rich Ulrich Date: Wed, 4 Jul 2012 02:50:20 -0700 From: [hidden email] Subject: Re: AW: Multiple Responses to Categories To: [hidden email]
Hi Gene / David, Sorry for that. Please, below you can find the data and syntax I was using: data list list /x1 to x13 . begin data 0 1 0 0 1 0 1 0 1 0 0 0 0 0 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 1 1 0 1 0 1 0 1 0 1 0 0 1 0 0 0 0 0 0 1 0 1 0 1 0 1 1 0 1 0 1 1 0 0 1 1 0 1 0 0 0 0 1 0 0 1 0 0 0 0 1 0 1 1 0 1 0 <snip, everything>.... |
In reply to this post by mils
If you have installed the Python Essentials
from the SPSS Community website (www.ibm.com/developerworks/spssdevcentral),
this little program will do it for any number of variables.
begin program. import spss, spssdata curs = spssdata.Spssdata(names=False) counts = {} for case in curs: counts[case] = counts.get(case, 0) + 1 curs.CClose() for item in sorted([(v,k) for k,v in counts.items()], reverse=True): print item end program The line following each for statement needs to be indented. The email sometimes mangles the format. Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] new phone: 720-342-5621 From: mils <[hidden email]> To: [hidden email] Date: 07/04/2012 10:05 AM Subject: Re: [SPSSX-L] AW: Multiple Responses to Categories Sent by: "SPSSX(r) Discussion" <[hidden email]> Hi Gene / David, Sorry for that. Please, below you can find the data and syntax I was using: data list list /x1 to x13 . begin data 0 1 0 0 1 0 1 0 1 0 0 0 0 0 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 1 1 0 1 0 1 0 1 0 1 0 0 1 0 0 0 0 0 0 1 0 1 0 1 0 1 1 0 1 0 1 1 0 0 1 1 0 1 0 0 0 0 1 0 0 1 0 0 0 0 1 0 1 1 0 1 0 1 0 1 0 1 0 0 1 0 0 0 0 0 0 1 0 1 0 1 0 1 1 0 1 0 1 1 0 0 1 1 0 1 0 0 0 0 1 0 0 1 0 0 0 0 1 0 1 1 0 1 0 0 1 0 0 1 0 1 0 1 1 0 1 0 1 0 1 0 1 0 0 1 0 0 0 0 0 0 1 0 1 0 1 0 1 1 0 1 0 1 1 0 0 1 1 0 1 0 0 0 0 1 0 1 0 0 1 1 0 1 0 0 0 0 1 0 0 1 0 0 0 0 1 0 1 1 0 1 0 1 0 1 0 1 0 0 1 0 0 0 0 0 0 1 0 1 0 1 0 1 1 0 1 0 1 1 0 0 1 1 0 1 0 0 0 0 1 0 0 1 0 0 0 0 1 0 1 1 0 1 0 end data. fre x1 to x13. *************David********************. COMPUTE ##=1. COMPUTE COMB=0. VECTOR X=X1 TO X13 / New(13). LOOP #=1 TO 13. + DO IF X(#)=1. + COMPUTE New(##)=#. + COMPUTE Comb=Comb*10+#. + COMPUTE ##=##+1. + END IF. END LOOP. EXE. FORMATS ALL (F3.0). list. fre comb. ****Output**** 1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 COMB New1 New2 New3 New4 New5 New6 New7 New8 New9 New10 New11 New12 New13 0 1 0 0 1 0 1 0 1 0 0 0 0 *** 2 5 7 9 . . . . . . . . . 0 0 1 0 0 1 0 1 0 1 0 0 1 *** 3 6 8 10 13 . . . . . . . . 0 1 0 0 1 0 1 0 1 1 0 1 0 *** 2 5 7 9 10 12 . . . . . . . 1 0 1 0 1 0 0 1 0 0 0 0 0 *** 1 3 5 8 . . . . . . . . . 0 1 0 1 0 1 0 1 1 0 1 0 1 *** 2 4 6 8 9 11 13 . . . . . . 1 0 0 1 1 0 1 0 0 0 0 1 0 *** 1 4 5 7 12 . . . . . . . . 0 1 0 0 0 0 1 0 1 1 0 1 0 *** 2 7 9 10 12 . . . . . . . . 1 0 1 0 1 0 0 1 0 0 0 0 0 *** 1 3 5 8 . . . . . . . . . 0 1 0 1 0 1 0 1 1 0 1 0 1 *** 2 4 6 8 9 11 13 . . . . . . 1 0 0 1 1 0 1 0 0 0 0 1 0 *** 1 4 5 7 12 . . . . . . . . 0 1 0 0 0 0 1 0 1 1 0 1 0 *** 2 7 9 10 12 . . . . . . . . 0 1 0 0 1 0 1 0 1 1 0 1 0 *** 2 5 7 9 10 12 . . . . . . . 1 0 1 0 1 0 0 1 0 0 0 0 0 *** 1 3 5 8 . . . . . . . . . 0 1 0 1 0 1 0 1 1 0 1 0 1 *** 2 4 6 8 9 11 13 . . . . . . 1 0 0 1 1 0 1 0 0 0 0 1 0 *** 1 4 5 7 12 . . . . . . . . 1 0 0 1 1 0 1 0 0 0 0 1 0 *** 1 4 5 7 12 . . . . . . . . 0 1 0 0 0 0 1 0 1 1 0 1 0 *** 2 7 9 10 12 . . . . . . . . 1 0 1 0 1 0 0 1 0 0 0 0 0 *** 1 3 5 8 . . . . . . . . . 0 1 0 1 0 1 0 1 1 0 1 0 1 *** 2 4 6 8 9 11 13 . . . . . . 1 0 0 1 1 0 1 0 0 0 0 1 0 *** 1 4 5 7 12 . . . . . . . . 0 1 0 0 0 0 1 0 1 1 0 1 0 *** 2 7 9 10 12 . . . . . . . . Number of cases read: 21 Number of cases listed: 21 *************Gene********************. Vector x=X1 TO X13/y=newvar1 to newvar13. Compute #j=1. Loop #i=1 to 13. + if (x(#i) eq 1) y(#j)=#i. + if (x(#i) eq 1) #j=#j+1. End loop. Vector x=x1 to x13. String combo(a3). Compute #j=1. Loop #i=1 to 13. + if (x(#i) eq 1) substr(combo,#j,1)='1'. + if (x(#i) eq 1) #j=#j+1. End loop. fre combo. ****there is no Output**** My objective is to find out which combinations is the most frequent amog the 13 variables and I would like to test it also with 100 variables or more if it is possible. Thanks in advance. Date: Tue, 3 Jul 2012 10:33:03 -0700 From: [hidden email] To: [hidden email] Subject: Re: AW: Multiple Responses to Categories Please post *EXACT* syntax you are using, sample input, output of what results *AND* what you believe the output should be. If you are attempting to store 'concatenated' list of MANY choices in a *NUMERIC* field you may wish to back your way out of the rabbit hole and take the red pill vs the blue one. ie Perhaps a STRING variable will be more appropriate. OTOH, meaningful interpretation of the resulting long string might cause you to go blond. What is it that you really wish to achieve from this exercise? --- mils wrote Hi Gene, Thanks for your post. It seems to work with 7 functions/variables, but I was testing it with 40 and I got weird outputs ...like: 37*. Any suggestions on how to improve the script using more than 7 variables? Lets say 100. Many Thanks! If you reply to this email, your message will be added to the discussion below: http://spssx-discussion.1045642.n5.nabble.com/AW-Multiple-Responses-to-Categories-tp5713788p5713990.html To unsubscribe from AW: Multiple Responses to Categories, click here. NAML View this message in context: RE: AW: Multiple Responses to Categories Sent from the SPSSX Discussion mailing list archive at Nabble.com. |
Administrator
|
In reply to this post by Rich Ulrich
OR use TEMPORARY prior to MISSING VALUES statement (assuming MVAP allows TEMP). No need to SORT first, AGGREGATE to my knowledge may have a limit but it would be large or you could build concatenations using base 10 multiplier as in my previous post and use those in the AGGREGATE break. OR maybe something like this but as warned previously the usefulness of the result might be underwhelming. STRING PATTERN(A200). DO REPEAT V=V1 TO V99/I=1 TO 99. IF V=1 SUBSTR(PATTERN,LENGTH(RTRIM(PATTERN))+1)=STRING(I,N2). END REPEAT. EXE. David --
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
Free forum by Nabble | Edit this page |