Hello,
I want to rearrange some data. At the moment the data is, simplified, given like this: A B C D_-2 D_-1 D_0 D_1 D_2 1 1 5 a b c d e 1 2 9 g c t f s ... Therefore C is connected to D_0, C-1 is connected to D_-1, C+2 is connected to D_2 and so on. In formulae, something of this form is represented: f(A,B)=((C-2,D_-2),(C-1,D_-1),(C,D_0),(C+1,D_1),(C+2,D_2)) Now this should be rearranged to a table representing: f(A,B)=(C-2,D_-2) f(A,B)=(C-1,D_-1) f(A,B)=(C,D_0) f(A,B)=(C+1,D_1) f(A,B)=(C+2,D_2) so the table should look like: A B C D 1 1 3 a 1 1 4 b 1 1 5 c 1 1 6 d 1 1 7 e 1 2 7 g 1 2 8 c 1 2 9 t 1 2 10 f 1 2 11 s I hope the problem is understandable. I also DO have a solution, programmed with Python: BEGIN PROGRAM. import spss read=spss.Cursor([0,1,2,3,4,5,6,7],'r') valueSet=read.fetchall() read.close() del read i=0 z=-2 while i<len(set(valueSet)): test=valueSet[i] i=i+1 while z<3: if z!=0: cur=spss.Cursor(accessType='a') cur.SetValueNumeric('A',test[0]) cur.SetValueNumeric('B',test[1]) cur.SetValueNumeric('C',test[2]+z) cur.SetValueNumeric('D_0',test[5+z]) cur.CommitCase() cur.EndChanges() cur.close() del cur z=z+1 z=-2 end program. My idea was to let the cases with (C,D_0) stay and just add the others. The problem is: I have 4530 cases. It runs till 6565 and then SPSS crashs ("An unknown error has terminated communication with the processor. The SPSS Statistics Processor is unavailable."). If I replace "while i<len(set(valueSet)):" with "while i<6:" it works, with 1000 instead of 6, it doesn't. Any ideas? Thank you in advance, SD. |
If I understand this correctly, I would calculate the extra 4 C variables (+ and -/1 and 2), then use the VARSTOCASES to restructure.
Something along the lines of... COMPUTE C_-2=C-2. etc... VARSTOCASES /index a(#) b(#) /MAKE C FROM C_-2 C_-1 C C_1 C_2 /MAKE D FROM D_-2 D_-1 D D_1 D_2 Where # is replaced by the number of values of a and b respectively. If I don't understand this correctly...please explain to the group. Melissa -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of SD Sent: Monday, January 14, 2013 8:58 AM To: [hidden email] Subject: [SPSSX-L] Add Vars to Cases Hello, I want to rearrange some data. At the moment the data is, simplified, given like this: A B C D_-2 D_-1 D_0 D_1 D_2 1 1 5 a b c d e 1 2 9 g c t f s ... Therefore C is connected to D_0, C-1 is connected to D_-1, C+2 is connected to D_2 and so on. In formulae, something of this form is represented: f(A,B)=((C-2,D_-2),(C-1,D_-1),(C,D_0),(C+1,D_1),(C+2,D_2)) Now this should be rearranged to a table representing: f(A,B)=(C-2,D_-2) f(A,B)=(C-1,D_-1) f(A,B)=(C,D_0) f(A,B)=(C+1,D_1) f(A,B)=(C+2,D_2) so the table should look like: A B C D 1 1 3 a 1 1 4 b 1 1 5 c 1 1 6 d 1 1 7 e 1 2 7 g 1 2 8 c 1 2 9 t 1 2 10 f 1 2 11 s I hope the problem is understandable. I also DO have a solution, programmed with Python: BEGIN PROGRAM. import spss read=spss.Cursor([0,1,2,3,4,5,6,7],'r') valueSet=read.fetchall() read.close() del read i=0 z=-2 while i<len(set(valueSet)): test=valueSet[i] i=i+1 while z<3: if z!=0: cur=spss.Cursor(accessType='a') cur.SetValueNumeric('A',test[0]) cur.SetValueNumeric('B',test[1]) cur.SetValueNumeric('C',test[2]+z) cur.SetValueNumeric('D_0',test[5+z]) cur.CommitCase() cur.EndChanges() cur.close() del cur z=z+1 z=-2 end program. My idea was to let the cases with (C,D_0) stay and just add the others. The problem is: I have 4530 cases. It runs till 6565 and then SPSS crashs ("An unknown error has terminated communication with the processor. The SPSS Statistics Processor is unavailable."). If I replace "while i<len(set(valueSet)):" with "while i<6:" it works, with 1000 instead of 6, it doesn't. Any ideas? Thank you in advance, SD. -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Add-Vars-to-Cases-tp5717359.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 PRIVILEGED AND CONFIDENTIAL INFORMATION This transmittal and any attachments may contain PRIVILEGED AND CONFIDENTIAL information and is intended only for the use of the addressee. If you are not the designated recipient, or an employee or agent authorized to deliver such transmittals to the designated recipient, you are hereby notified that any dissemination, copying or publication of this transmittal is strictly prohibited. If you have received this transmittal in error, please notify us immediately by replying to the sender and delete this copy from your system. You may also call us at (309) 827-6026 for assistance. ===================== 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 |
Administrator
|
In reply to this post by SD
What horrible overkill (python)!!!
Just use VARSTOCASES create an INDEX and calculate your new variable from that. KISS!!!! -- <quote author="SD"> Hello, I want to rearrange some data. At the moment the data is, simplified, given like this: A B C D_-2 D_-1 D_0 D_1 D_2 1 1 5 a b c d e 1 2 9 g c t f s ... Therefore C is connected to D_0, C-1 is connected to D_-1, C+2 is connected to D_2 and so on. In formulae, something of this form is represented: f(A,B)=((C-2,D_-2),(C-1,D_-1),(C,D_0),(C+1,D_1),(C+2,D_2)) Now this should be rearranged to a table representing: f(A,B)=(C-2,D_-2) f(A,B)=(C-1,D_-1) f(A,B)=(C,D_0) f(A,B)=(C+1,D_1) f(A,B)=(C+2,D_2) so the table should look like: A B C D 1 1 3 a 1 1 4 b 1 1 5 c 1 1 6 d 1 1 7 e 1 2 7 g 1 2 8 c 1 2 9 t 1 2 10 f 1 2 11 s I hope the problem is understandable. I also DO have a solution, programmed with Python: BEGIN PROGRAM. import spss read=spss.Cursor([0,1,2,3,4,5,6,7],'r') valueSet=read.fetchall() read.close() del read i=0 z=-2 while i<len(set(valueSet)): test=valueSet[i] i=i+1 while z<3: if z!=0: cur=spss.Cursor(accessType='a') cur.SetValueNumeric('A',test[0]) cur.SetValueNumeric('B',test[1]) cur.SetValueNumeric('C',test[2]+z) cur.SetValueNumeric('D_0',test[5+z]) cur.CommitCase() cur.EndChanges() cur.close() del cur z=z+1 z=-2 end program. My idea was to let the cases with (C,D_0) stay and just add the others. The problem is: I have 4530 cases. It runs till 6565 and then SPSS crashs ("An unknown error has terminated communication with the processor. The SPSS Statistics Processor is unavailable."). If I replace "while i<len(set(valueSet)):" with "while i<6:" it works, with 1000 instead of 6, it doesn't. Any ideas? Thank you in advance, SD. </quote>
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?" |
Administrator
|
Seriously!!!
Only use python when you REALLY FREAKING NEED IT AND THERE IS NO OTHER ALTERNATIVE!!!!!! --- DATA LIST LIST / A B C (3F2) D_M2 D_M1 D_0 D_1 D_2 (5A1). BEGIN DATA 1 1 5 a b c d e 1 2 9 g c t f s END DATA. LIST. VARSTOCASES /ID = B /MAKE D FROM D_M2 D_M1 D_0 D_1 D_2 /INDEX = Index1(5) /KEEP = A C. COMPUTE NewC=C+Index1-3. EXE. <quote author="David Marso"> What horrible overkill (python)!!! Just use VARSTOCASES create an INDEX and calculate your new variable from that. KISS!!!! --
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?" |
Thank you two.
I didn't see another solution, so I thought one solution is better than none ;). But since it didn't work, it wasn't better... I adapt Davids solution and its working good, so thanks again. |
In reply to this post by David Marso
Just like Macros,
Matrix, or scripts.
Art Kendall Social Research ConsultantsOn 1/14/2013 7:12 PM, David Marso wrote: Seriously!!! Only use python when you REALLY FREAKING NEED IT AND THERE IS NO OTHER ALTERNATIVE!!!!!! --- DATA LIST LIST / A B C (3F2) D_M2 D_M1 D_0 D_1 D_2 (5A1). BEGIN DATA 1 1 5 a b c d e 1 2 9 g c t f s END DATA. LIST. VARSTOCASES /ID = B /MAKE D FROM D_M2 D_M1 D_0 D_1 D_2 /INDEX = Index1(5) /KEEP = A C. COMPUTE NewC=C+Index1-3. EXE. What horrible overkill (python)!!! Just use VARSTOCASES create an INDEX and calculate your new variable from that. KISS!!!! -- SD wroteHello, I want to rearrange some data. At the moment the data is, simplified, given like this: A B C D_-2 D_-1 D_0 D_1 D_2 1 1 5 a b c d e 1 2 9 g c t f s ... Therefore C is connected to D_0, C-1 is connected to D_-1, C+2 is connected to D_2 and so on. In formulae, something of this form is represented: f(A,B)=((C-2,D_-2),(C-1,D_-1),(C,D_0),(C+1,D_1),(C+2,D_2)) Now this should be rearranged to a table representing: f(A,B)=(C-2,D_-2) f(A,B)=(C-1,D_-1) f(A,B)=(C,D_0) f(A,B)=(C+1,D_1) f(A,B)=(C+2,D_2) so the table should look like: A B C D 1 1 3 a 1 1 4 b 1 1 5 c 1 1 6 d 1 1 7 e 1 2 7 g 1 2 8 c 1 2 9 t 1 2 10 f 1 2 11 s I hope the problem is understandable. I also DO have a solution, programmed with Python: BEGIN PROGRAM. import spss read=spss.Cursor([0,1,2,3,4,5,6,7],'r') valueSet=read.fetchall() read.close() del read i=0 z=-2 while i<len(set(valueSet)): test=valueSet[i] i=i+1 while z<3: if z!=0: cur=spss.Cursor(accessType='a') cur.SetValueNumeric('A',test[0]) cur.SetValueNumeric('B',test[1]) cur.SetValueNumeric('C',test[2]+z) cur.SetValueNumeric('D_0',test[5+z]) cur.CommitCase() cur.EndChanges() cur.close() del cur z=z+1 z=-2 end program. My idea was to let the cases with (C,D_0) stay and just add the others. The problem is: I have 4530 cases. It runs till 6565 and then SPSS crashs ("An unknown error has terminated communication with the processor. The SPSS Statistics Processor is unavailable."). If I replace "while i<len(set(valueSet)):" with "while i<6:" it works, with 1000 instead of 6, it doesn't. Any ideas? Thank you in advance, SD. </quote>----- Please reply to the list and not to my personal email. Those desiring my consulting or training services please feel free to email me. -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Add-Vars-to-Cases-tp5717359p5717375.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
Art Kendall
Social Research Consultants |
Administrator
|
Ultimately it is a matter of tools/scope/context. If one only has a shovel then one can only dig holes.
It is possible to get by without any macros, matrix, scripting, python (hell, we did just ?fine? for many years)--- I could probably write a book about when/where/why one would wish to use one or another or all in combination. My primary guiding principle is KISS (keep it stupidly simple).
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?" |
Ultimately it is a matter of tools/scope/contextSo true. I did not go back through the archives to refresh my memory. However, IIRC, there have been many instances, where people asked about OMS, macros, python, etc. when the list came up with straight forward ways to do what was needed using options/commands in SPSS that the OP did not know existed. My experience in all kinds of consulting/counseling that the "presenting question is seldom the actual question". You may have noticed that often my first response to a post is to ask more questions. I would expand KISS a little bit and say "keep it stupidly simple and readable". Art Kendall Social Research ConsultantsOn 1/15/2013 9:31 AM, David Marso wrote: Ultimately it is a matter of tools/scope/context. If one only has a shovel then one can only dig holes. It is possible to get by without any macros, matrix, scripting, python (hell, we did just ?fine? for many years)--- I could probably write a book about when/where/why one would wish to use one or another or all in combination. My primary guiding principle is KISS (keep it stupidly simple). Art Kendall wroteJust like Macros, Matrix, or scripts. Art Kendall Social Research Consultants On 1/14/2013 7:12 PM, David Marso wrote: Seriously!!! Only use python when you REALLY FREAKING NEED IT AND THERE IS NO OTHER ALTERNATIVE!!!!!! --- DATA LIST LIST / A B C (3F2) D_M2 D_M1 D_0 D_1 D_2 (5A1). BEGIN DATA 1 1 5 a b c d e 1 2 9 g c t f s END DATA. LIST. VARSTOCASES /ID = B /MAKE D FROM D_M2 D_M1 D_0 D_1 D_2 /INDEX = Index1(5) /KEEP = A C. COMPUTE NewC=C+Index1-3. EXE. What horrible overkill (python)!!! Just use VARSTOCASES create an INDEX and calculate your new variable from that. KISS!!!! -- SD wrote Hello, I want to rearrange some data. At the moment the data is, simplified, given like this: A B C D_-2 D_-1 D_0 D_1 D_2 1 1 5 a b c d e 1 2 9 g c t f s ... Therefore C is connected to D_0, C-1 is connected to D_-1, C+2 is connected to D_2 and so on. In formulae, something of this form is represented: f(A,B)=((C-2,D_-2),(C-1,D_-1),(C,D_0),(C+1,D_1),(C+2,D_2)) Now this should be rearranged to a table representing: f(A,B)=(C-2,D_-2) f(A,B)=(C-1,D_-1) f(A,B)=(C,D_0) f(A,B)=(C+1,D_1) f(A,B)=(C+2,D_2) so the table should look like: A B C D 1 1 3 a 1 1 4 b 1 1 5 c 1 1 6 d 1 1 7 e 1 2 7 g 1 2 8 c 1 2 9 t 1 2 10 f 1 2 11 s I hope the problem is understandable. I also DO have a solution, programmed with Python: BEGIN PROGRAM. import spss read=spss.Cursor([0,1,2,3,4,5,6,7],'r') valueSet=read.fetchall() read.close() del read i=0 z=-2 while i&lt;len(set(valueSet)): test=valueSet[i] i=i+1 while z&lt;3: if z!=0: cur=spss.Cursor(accessType='a') cur.SetValueNumeric('A',test[0]) cur.SetValueNumeric('B',test[1]) cur.SetValueNumeric('C',test[2]+z) cur.SetValueNumeric('D_0',test[5+z]) cur.CommitCase() cur.EndChanges() cur.close() del cur z=z+1 z=-2 end program. My idea was to let the cases with (C,D_0) stay and just add the others. The problem is: I have 4530 cases. It runs till 6565 and then SPSS crashs (&quot;An unknown error has terminated communication with the processor. The SPSS Statistics Processor is unavailable.&quot;). If I replace &quot;while i&lt;len(set(valueSet)):&quot; with &quot;while i&lt;6:&quot; it works, with 1000 instead of 6, it doesn't. Any ideas? Thank you in advance, SD. &lt;/quote&gt; ----- Please reply to the list and not to my personal email. Those desiring my consulting or training services please feel free to email me. -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Add-Vars-to-Cases-tp5717359p5717375.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----- Please reply to the list and not to my personal email. Those desiring my consulting or training services please feel free to email me. -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Add-Vars-to-Cases-tp5717359p5717389.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
Art Kendall
Social Research Consultants |
Administrator
|
"My experience in all kinds of consulting/counseling that the "presenting question is seldom the actual question."
When the god's are smiling upon you! Example of a worst case scenario which ultimately evolved into a great situation. Contract hire as an statistical analyst for a short term project (3 mo). Enter stage left: Review of current code? Classic example of probably 10-15 of my recently posted '20 horrible coding practices'. Day1-Day3: Clean up code. Review with coworkers. Blow several minds with Macro refactoring. Day4-Day5: Reassigned to put out raging fire to extract critical data from completely alien data base. Day6-Day8: Design scripting automation to serialize SPSS objects into Excel (replacing painful time consuming copy paste process). Day9-Day10: Shudder as 'big picture' of ultimate deliverable is revealed in somewhat blurry fashion. -Connect Access database with SPSS to generate output and serialize into Powerpoint- End of day 10: discover that Access/Powerpoint person is a 'graphic designer' who has never programmed in his life and has built the 'database' and some of the powerpoint templates using the evil M$ wizards to belch out incomprehensible gibberish (meanwhile comforting myself that I will never have to touch that crap). Day11: Request design documents. End of Day11: Receive email that no such documents exist. Day12-Day45: Put out various fires, optimize various critical operational reporting procedures,ask lots of questions, offer my soul to the devil in trade for some breadcrumbs to sort out the wreckage. Almost take up drinking again after 1 year dry. Day46: Word that Access/Powerpoint dude is taking 2 wk vacation to HI. Middle of day46: 3rd request for current projects/documentation from A/P dude. End of Day46 : Verbally 'Waterboard' A/P dude for critical info (eventually received files but no docs). Day47-Day48 : Upon review reluctantly arrive at grim conclusion that 'design' is a terminal RCI induced anti-pattern and that we are most likely doomed. Day49-Day51 : Totally redesign application and request confirmation of match to requirements. --NOTE DO-OR-DIE-DEADLINE --> 9 days!! Day51-Day56 : Scramble like a maniac to build what should have been designed and partially created when I signed on. Day56: Receive word that A/P dude is not coming back from HI (ok who cares!... Powers that be decide it important to fly dude back for a day to 'help'). Day57: Waste entire day attempting to extract anything useful from A/P dude. Day58: Bust ass and finalize alpha version. End of Day58: Receive word that certain critical (difficult to implement) functionality (not present in SOR) is not present. End of End of Day58: Do an all nighter to add D2INPISOR crap... Day59: Finally get the bastard to run (sort of). Fix A/P/D ugly hack which resulted in 'sort of'. Day60: Present application to client... Ooooh Ahhhhhh!!!! (If they only knew the shameless crap living in the bowels of that beast). ----- Odd: I didn't do any statistical analytical work at all during that gig. ----------------------------------------------------------------------------- Day61 Got contract renewal with request to build a 'special application' from ground up with complete control of all design/implementation and general access to end users (internal) to ascertain requirements. Day62-Day90: Design/Build/Prototype/Code/User Input: ITERATE. Day91: Entire FTP staff heads to Greece for 2 weeks to celebrate wedding of primary 'special application' recipient. Day91-Day100: Program distraction free and completely exceed expectations of end users. Yeah, With minimal effort added a few really nice features which were not necessary but were very useful. Day101 Everyone's back from Greece: Demo: Oohhhh Ahhhhhh DAVID WE LOVE YOU!!!! ----- Cliff Notes version: Jump into a raging fire on a speeding train with the next bridge out wearing only teflon underwear and somehow pull a magical brown rabbit out of my ass! ----- Ahhh the life!!! -----------------------------------------------
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 |