|
Because I've already received requests to see the actual code, I am
pasting my previous message along with the full code at the end. ---- I am writing a syntax file that, when run, reads in files, does some processing, and "spits out" new files. The processing includes a short piece of Python code. Initially, the syntax I wrote did this only for one file, and then I created a macro with loops (with the help of some very helpful people on this mailing list) to make it repeat the process for over 1,000 files. Before the loops, the syntax would run very quickly. As it ran, at the bottom of each window, it would tell me what exactly it was doing at that moment (e.g. Running COMPUTE, Running EXECUTE, Running BEGIN PROGRAM, etc). Now I have added the loops and am trying to run it; for the first few minutes, the text on the bottom reads "Running DEFINE". This makes sense to me, as it is parsing a LOT of lines. The next thing that appears for any significant length of time is "Running PROGRAM>...", and at this point, it appears to freeze. It does not matter how long I wait; it does not come out of this state. This was not a message that ever appeared before the loops. The output window shows no errors. Does anybody know what could be wrong? Thank you in advance! -Greg ---- DEFINE listvars() !DO !v=1 !TO 440 !LET !nam=!CONCAT("V",!v," F9.7") !nam !DOEND !ENDDEFINE. DEFINE mainsub (VLIST1=!ENCLOSE('(',')') / VLIST2=!ENCLOSE('(',')') / VLIST3=!ENCLOSE('(',')') / VLIST4=!ENCLOSE('(',')') / VLIST5=!ENCLOSE('(',')')) !DO !sub !IN (!VLIST1) !DO !trg !IN (!VLIST2) !DO !con !IN (!VLIST3) !DO !roi !IN (!VLIST4) !DO !hemi !IN (!VLIST5) !LET !file=!CONCAT("sub",!sub,"_",!trg,"_",!con,"_",!roi,"_",!hemi) !LET !amp=!CONCAT(!file,".amp") !LET !outfile=!CONCAT(!file,".txt") GET DATA /TYPE = TXT /FILE = !CONCAT("'C:\amp\",!amp,"'") /DELCASE = LINE /DELIMITERS = " " /ARRANGEMENT = DELIMITED /FIRSTCASE = 2 /IMPORTCASE = ALL /VARIABLES = listvars CACHE. DATASET NAME Raw. COMPUTE B120=MEAN(V1 TO V11) . COMPUTE B140=MEAN(V12 TO V21) . COMPUTE B160=MEAN(V22 TO V31) . COMPUTE B180=MEAN(V32 TO V41) . COMPUTE B200=MEAN(V42 TO V51) . COMPUTE B220=MEAN(V52 TO V61) . COMPUTE B240=MEAN(V62 TO V72) . COMPUTE B260=MEAN(V73 TO V82) . COMPUTE B280=MEAN(V83 TO V92) . COMPUTE B300=MEAN(V93 TO V102) . COMPUTE B320=MEAN(V103 TO V112) . COMPUTE B340=MEAN(V113 TO V122) . COMPUTE B360=MEAN(V123 TO V133) . COMPUTE B380=MEAN(V134 TO V143) . COMPUTE B400=MEAN(V144 TO V153) . COMPUTE B420=MEAN(V154 TO V163) . COMPUTE B440=MEAN(V164 TO V173) . COMPUTE B460=MEAN(V174 TO V183) . COMPUTE B480=MEAN(V184 TO V194) . COMPUTE B500=MEAN(V195 TO V204) . COMPUTE B520=MEAN(V205 TO V214) . COMPUTE B540=MEAN(V215 TO V224) . COMPUTE B560=MEAN(V225 TO V234) . COMPUTE B580=MEAN(V235 TO V245) . COMPUTE B600=MEAN(V246 TO V255) . COMPUTE B620=MEAN(V256 TO V265) . COMPUTE B640=MEAN(V266 TO V275) . COMPUTE B660=MEAN(V276 TO V285) . COMPUTE B680=MEAN(V286 TO V295) . COMPUTE B700=MEAN(V296 TO V306) . COMPUTE B720=MEAN(V307 TO V316) . COMPUTE B740=MEAN(V317 TO V326) . COMPUTE B760=MEAN(V327 TO V336) . COMPUTE B780=MEAN(V337 TO V346) . COMPUTE B800=MEAN(V347 TO V356) . COMPUTE B820=MEAN(V357 TO V367) . COMPUTE B840=MEAN(V368 TO V377) . COMPUTE B860=MEAN(V378 TO V387) . COMPUTE B880=MEAN(V388 TO V397) . COMPUTE B900=MEAN(V398 TO V407) . COMPUTE B920=MEAN(V408 TO V417) . COMPUTE B940=MEAN(V418 TO V428) . COMPUTE B960=MEAN(V429 TO V438) . FLIP VARIABLES=B120 TO B960 . DATASET CLOSE Raw. DELETE VARIABLES CASE_LBL. BEGIN PROGRAM. import spss c = spss.GetVariableCount() v0 = spss.GetVariableName(0) vn = spss.GetVariableName(c-1) mean = "COMPUTE MEAN = MEAN(%(v0)s TO %(vn)s)" % locals() stderr = "COMPUTE STDERR = SD(%(v0)s TO %(vn)s)/SQRT(%(c)s)" % locals() dele = "DELETE VARIABLES %(v0)s TO %(vn)s" % locals() spss.Submit(mean) spss.Submit(stderr) spss.Submit("EXECUTE.") spss.Submit(dele) END PROGRAM. FLIP VARIABLES=ALL. WRITE OUTFILE=!CONCAT("'C:\out\",!outfile,"'") /ALL. EXECUTE. !DOEND !DOEND !DOEND !DOEND !DOEND !ENDDEFINE. mainsub VLIST1 (009 016 022 047 099) VLIST2 (v t dw) VLIST3 (in ms un) VLIST4 (parsopercularis parstriangularis lateralorbitofrontal superiortemporal supramarginal superiorfrontal rostralmiddlefrontal caudalmiddlefrontal parsorbitalis angular_gyrus) VLIST5 (lh rh). ===================== 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 |
|
You have a Python program block inside a Define-!Enddefine macro definition. That won't work. According to the SPSS Help:
Program blocks cannot be contained within DEFINE-!ENDDEFINE macro definitions. ________________________________ From: SPSSX(r) Discussion on behalf of Greg Chulsky Sent: Wed 8/27/2008 7:46 PM To: [hidden email] Subject: UPDATED: Running PROGRAM>... Because I've already received requests to see the actual code, I am pasting my previous message along with the full code at the end. ---- I am writing a syntax file that, when run, reads in files, does some processing, and "spits out" new files. The processing includes a short piece of Python code. Initially, the syntax I wrote did this only for one file, and then I created a macro with loops (with the help of some very helpful people on this mailing list) to make it repeat the process for over 1,000 files. Before the loops, the syntax would run very quickly. As it ran, at the bottom of each window, it would tell me what exactly it was doing at that moment (e.g. Running COMPUTE, Running EXECUTE, Running BEGIN PROGRAM, etc). Now I have added the loops and am trying to run it; for the first few minutes, the text on the bottom reads "Running DEFINE". This makes sense to me, as it is parsing a LOT of lines. The next thing that appears for any significant length of time is "Running PROGRAM>...", and at this point, it appears to freeze. It does not matter how long I wait; it does not come out of this state. This was not a message that ever appeared before the loops. The output window shows no errors. Does anybody know what could be wrong? Thank you in advance! -Greg ---- DEFINE listvars() !DO !v=1 !TO 440 !LET !nam=!CONCAT("V",!v," F9.7") !nam !DOEND !ENDDEFINE. DEFINE mainsub (VLIST1=!ENCLOSE('(',')') / VLIST2=!ENCLOSE('(',')') / VLIST3=!ENCLOSE('(',')') / VLIST4=!ENCLOSE('(',')') / VLIST5=!ENCLOSE('(',')')) !DO !sub !IN (!VLIST1) !DO !trg !IN (!VLIST2) !DO !con !IN (!VLIST3) !DO !roi !IN (!VLIST4) !DO !hemi !IN (!VLIST5) !LET !file=!CONCAT("sub",!sub,"_",!trg,"_",!con,"_",!roi,"_",!hemi) !LET !amp=!CONCAT(!file,".amp") !LET !outfile=!CONCAT(!file,".txt") GET DATA /TYPE = TXT /FILE = !CONCAT("'C:\amp\",!amp,"'") /DELCASE = LINE /DELIMITERS = " " /ARRANGEMENT = DELIMITED /FIRSTCASE = 2 /IMPORTCASE = ALL /VARIABLES = listvars CACHE. DATASET NAME Raw. COMPUTE B120=MEAN(V1 TO V11) . COMPUTE B140=MEAN(V12 TO V21) . COMPUTE B160=MEAN(V22 TO V31) . COMPUTE B180=MEAN(V32 TO V41) . COMPUTE B200=MEAN(V42 TO V51) . COMPUTE B220=MEAN(V52 TO V61) . COMPUTE B240=MEAN(V62 TO V72) . COMPUTE B260=MEAN(V73 TO V82) . COMPUTE B280=MEAN(V83 TO V92) . COMPUTE B300=MEAN(V93 TO V102) . COMPUTE B320=MEAN(V103 TO V112) . COMPUTE B340=MEAN(V113 TO V122) . COMPUTE B360=MEAN(V123 TO V133) . COMPUTE B380=MEAN(V134 TO V143) . COMPUTE B400=MEAN(V144 TO V153) . COMPUTE B420=MEAN(V154 TO V163) . COMPUTE B440=MEAN(V164 TO V173) . COMPUTE B460=MEAN(V174 TO V183) . COMPUTE B480=MEAN(V184 TO V194) . COMPUTE B500=MEAN(V195 TO V204) . COMPUTE B520=MEAN(V205 TO V214) . COMPUTE B540=MEAN(V215 TO V224) . COMPUTE B560=MEAN(V225 TO V234) . COMPUTE B580=MEAN(V235 TO V245) . COMPUTE B600=MEAN(V246 TO V255) . COMPUTE B620=MEAN(V256 TO V265) . COMPUTE B640=MEAN(V266 TO V275) . COMPUTE B660=MEAN(V276 TO V285) . COMPUTE B680=MEAN(V286 TO V295) . COMPUTE B700=MEAN(V296 TO V306) . COMPUTE B720=MEAN(V307 TO V316) . COMPUTE B740=MEAN(V317 TO V326) . COMPUTE B760=MEAN(V327 TO V336) . COMPUTE B780=MEAN(V337 TO V346) . COMPUTE B800=MEAN(V347 TO V356) . COMPUTE B820=MEAN(V357 TO V367) . COMPUTE B840=MEAN(V368 TO V377) . COMPUTE B860=MEAN(V378 TO V387) . COMPUTE B880=MEAN(V388 TO V397) . COMPUTE B900=MEAN(V398 TO V407) . COMPUTE B920=MEAN(V408 TO V417) . COMPUTE B940=MEAN(V418 TO V428) . COMPUTE B960=MEAN(V429 TO V438) . FLIP VARIABLES=B120 TO B960 . DATASET CLOSE Raw. DELETE VARIABLES CASE_LBL. BEGIN PROGRAM. import spss c = spss.GetVariableCount() v0 = spss.GetVariableName(0) vn = spss.GetVariableName(c-1) mean = "COMPUTE MEAN = MEAN(%(v0)s TO %(vn)s)" % locals() stderr = "COMPUTE STDERR = SD(%(v0)s TO %(vn)s)/SQRT(%(c)s)" % locals() dele = "DELETE VARIABLES %(v0)s TO %(vn)s" % locals() spss.Submit(mean) spss.Submit(stderr) spss.Submit("EXECUTE.") spss.Submit(dele) END PROGRAM. FLIP VARIABLES=ALL. WRITE OUTFILE=!CONCAT("'C:\out\",!outfile,"'") /ALL. EXECUTE. !DOEND !DOEND !DOEND !DOEND !DOEND !ENDDEFINE. mainsub VLIST1 (009 016 022 047 099) VLIST2 (v t dw) VLIST3 (in ms un) VLIST4 (parsopercularis parstriangularis lateralorbitofrontal superiortemporal supramarginal superiorfrontal rostralmiddlefrontal caudalmiddlefrontal parsorbitalis angular_gyrus) VLIST5 (lh rh). ===================== 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 |
|
Ouch! Thank you. I didn't catch that. Is there any way to circumvent
that problem? The program block needs to be repeated in every iteration of the loop, and what it does cannot be done with syntax alone. Oliver, Richard wrote: > You have a Python program block inside a Define-!Enddefine macro definition. That won't work. According to the SPSS Help: > > Program blocks cannot be contained within DEFINE-!ENDDEFINE macro definitions. > > ________________________________ > > From: SPSSX(r) Discussion on behalf of Greg Chulsky > Sent: Wed 8/27/2008 7:46 PM > To: [hidden email] > Subject: UPDATED: Running PROGRAM>... > > > > Because I've already received requests to see the actual code, I am > pasting my previous message along with the full code at the end. > > ---- > I am writing a syntax file that, when run, reads in files, does some > processing, and "spits out" new files. The processing includes a short > piece of Python code. Initially, the syntax I wrote did this only for > one file, and then I created a macro with loops (with the help of some > very helpful people on this mailing list) to make it repeat the process > for over 1,000 files. > > Before the loops, the syntax would run very quickly. As it ran, at the > bottom of each window, it would tell me what exactly it was doing at > that moment (e.g. Running COMPUTE, Running EXECUTE, Running BEGIN > PROGRAM, etc). > > Now I have added the loops and am trying to run it; for the first few > minutes, the text on the bottom reads "Running DEFINE". This makes > sense to me, as it is parsing a LOT of lines. The next thing that > appears for any significant length of time is "Running PROGRAM>...", and > at this point, it appears to freeze. It does not matter how long I > wait; it does not come out of this state. This was not a message that > ever appeared before the loops. The output window shows no errors. > > Does anybody know what could be wrong? Thank you in advance! > > -Greg > ---- > > DEFINE listvars() > !DO !v=1 !TO 440 > !LET !nam=!CONCAT("V",!v," F9.7") > !nam > !DOEND > !ENDDEFINE. > > DEFINE mainsub (VLIST1=!ENCLOSE('(',')') / VLIST2=!ENCLOSE('(',')') / > VLIST3=!ENCLOSE('(',')') / VLIST4=!ENCLOSE('(',')') / > VLIST5=!ENCLOSE('(',')')) > !DO !sub !IN (!VLIST1) > !DO !trg !IN (!VLIST2) > !DO !con !IN (!VLIST3) > !DO !roi !IN (!VLIST4) > !DO !hemi !IN (!VLIST5) > > !LET !file=!CONCAT("sub",!sub,"_",!trg,"_",!con,"_",!roi,"_",!hemi) > !LET !amp=!CONCAT(!file,".amp") > !LET !outfile=!CONCAT(!file,".txt") > > GET DATA /TYPE = TXT > /FILE = !CONCAT("'C:\amp\",!amp,"'") > /DELCASE = LINE > /DELIMITERS = " " > /ARRANGEMENT = DELIMITED > /FIRSTCASE = 2 > /IMPORTCASE = ALL > /VARIABLES = listvars > > CACHE. > DATASET NAME Raw. > > COMPUTE B120=MEAN(V1 TO V11) . > COMPUTE B140=MEAN(V12 TO V21) . > COMPUTE B160=MEAN(V22 TO V31) . > COMPUTE B180=MEAN(V32 TO V41) . > COMPUTE B200=MEAN(V42 TO V51) . > COMPUTE B220=MEAN(V52 TO V61) . > COMPUTE B240=MEAN(V62 TO V72) . > COMPUTE B260=MEAN(V73 TO V82) . > COMPUTE B280=MEAN(V83 TO V92) . > COMPUTE B300=MEAN(V93 TO V102) . > COMPUTE B320=MEAN(V103 TO V112) . > COMPUTE B340=MEAN(V113 TO V122) . > COMPUTE B360=MEAN(V123 TO V133) . > COMPUTE B380=MEAN(V134 TO V143) . > COMPUTE B400=MEAN(V144 TO V153) . > COMPUTE B420=MEAN(V154 TO V163) . > COMPUTE B440=MEAN(V164 TO V173) . > COMPUTE B460=MEAN(V174 TO V183) . > COMPUTE B480=MEAN(V184 TO V194) . > COMPUTE B500=MEAN(V195 TO V204) . > COMPUTE B520=MEAN(V205 TO V214) . > COMPUTE B540=MEAN(V215 TO V224) . > COMPUTE B560=MEAN(V225 TO V234) . > COMPUTE B580=MEAN(V235 TO V245) . > COMPUTE B600=MEAN(V246 TO V255) . > COMPUTE B620=MEAN(V256 TO V265) . > COMPUTE B640=MEAN(V266 TO V275) . > COMPUTE B660=MEAN(V276 TO V285) . > COMPUTE B680=MEAN(V286 TO V295) . > COMPUTE B700=MEAN(V296 TO V306) . > COMPUTE B720=MEAN(V307 TO V316) . > COMPUTE B740=MEAN(V317 TO V326) . > COMPUTE B760=MEAN(V327 TO V336) . > COMPUTE B780=MEAN(V337 TO V346) . > COMPUTE B800=MEAN(V347 TO V356) . > COMPUTE B820=MEAN(V357 TO V367) . > COMPUTE B840=MEAN(V368 TO V377) . > COMPUTE B860=MEAN(V378 TO V387) . > COMPUTE B880=MEAN(V388 TO V397) . > COMPUTE B900=MEAN(V398 TO V407) . > COMPUTE B920=MEAN(V408 TO V417) . > COMPUTE B940=MEAN(V418 TO V428) . > COMPUTE B960=MEAN(V429 TO V438) . > > FLIP > VARIABLES=B120 TO B960 . > > DATASET CLOSE Raw. > > DELETE VARIABLES CASE_LBL. > > BEGIN PROGRAM. > import spss > c = spss.GetVariableCount() > v0 = spss.GetVariableName(0) > vn = spss.GetVariableName(c-1) > mean = "COMPUTE MEAN = MEAN(%(v0)s TO %(vn)s)" % locals() > stderr = "COMPUTE STDERR = SD(%(v0)s TO %(vn)s)/SQRT(%(c)s)" % locals() > dele = "DELETE VARIABLES %(v0)s TO %(vn)s" % locals() > spss.Submit(mean) > spss.Submit(stderr) > spss.Submit("EXECUTE.") > spss.Submit(dele) > END PROGRAM. > > FLIP > VARIABLES=ALL. > > WRITE OUTFILE=!CONCAT("'C:\out\",!outfile,"'") > /ALL. > EXECUTE. > > !DOEND > !DOEND > !DOEND > !DOEND > !DOEND > !ENDDEFINE. > > mainsub VLIST1 (009 016 022 047 099) VLIST2 (v t dw) VLIST3 (in ms un) > VLIST4 (parsopercularis parstriangularis lateralorbitofrontal > superiortemporal supramarginal superiorfrontal rostralmiddlefrontal > caudalmiddlefrontal parsorbitalis angular_gyrus) > VLIST5 (lh rh). ===================== 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 |
|
Turn it around: Can what the macro is doing be done in Python instead? I'm not sure what the macro is doing, so I can't answer that question.
________________________________ From: SPSSX(r) Discussion on behalf of Greg Chulsky Sent: Thu 8/28/2008 12:00 AM To: [hidden email] Subject: Re: UPDATED: Running PROGRAM>... Ouch! Thank you. I didn't catch that. Is there any way to circumvent that problem? The program block needs to be repeated in every iteration of the loop, and what it does cannot be done with syntax alone. Oliver, Richard wrote: > You have a Python program block inside a Define-!Enddefine macro definition. That won't work. According to the SPSS Help: > > Program blocks cannot be contained within DEFINE-!ENDDEFINE macro definitions. > > ________________________________ > > From: SPSSX(r) Discussion on behalf of Greg Chulsky > Sent: Wed 8/27/2008 7:46 PM > To: [hidden email] > Subject: UPDATED: Running PROGRAM>... > > > > Because I've already received requests to see the actual code, I am > pasting my previous message along with the full code at the end. > > ---- > I am writing a syntax file that, when run, reads in files, does some > processing, and "spits out" new files. The processing includes a short > piece of Python code. Initially, the syntax I wrote did this only for > one file, and then I created a macro with loops (with the help of some > very helpful people on this mailing list) to make it repeat the process > for over 1,000 files. > > Before the loops, the syntax would run very quickly. As it ran, at the > bottom of each window, it would tell me what exactly it was doing at > that moment (e.g. Running COMPUTE, Running EXECUTE, Running BEGIN > PROGRAM, etc). > > Now I have added the loops and am trying to run it; for the first few > minutes, the text on the bottom reads "Running DEFINE". This makes > sense to me, as it is parsing a LOT of lines. The next thing that > appears for any significant length of time is "Running PROGRAM>...", and > at this point, it appears to freeze. It does not matter how long I > wait; it does not come out of this state. This was not a message that > ever appeared before the loops. The output window shows no errors. > > Does anybody know what could be wrong? Thank you in advance! > > -Greg > ---- > > DEFINE listvars() > !DO !v=1 !TO 440 > !LET !nam=!CONCAT("V",!v," F9.7") > !nam > !DOEND > !ENDDEFINE. > > DEFINE mainsub (VLIST1=!ENCLOSE('(',')') / VLIST2=!ENCLOSE('(',')') / > VLIST3=!ENCLOSE('(',')') / VLIST4=!ENCLOSE('(',')') / > VLIST5=!ENCLOSE('(',')')) > !DO !sub !IN (!VLIST1) > !DO !trg !IN (!VLIST2) > !DO !con !IN (!VLIST3) > !DO !roi !IN (!VLIST4) > !DO !hemi !IN (!VLIST5) > > !LET !file=!CONCAT("sub",!sub,"_",!trg,"_",!con,"_",!roi,"_",!hemi) > !LET !amp=!CONCAT(!file,".amp") > !LET !outfile=!CONCAT(!file,".txt") > > GET DATA /TYPE = TXT > /FILE = !CONCAT("'C:\amp\",!amp,"'") > /DELCASE = LINE > /DELIMITERS = " " > /ARRANGEMENT = DELIMITED > /FIRSTCASE = 2 > /IMPORTCASE = ALL > /VARIABLES = listvars > > CACHE. > DATASET NAME Raw. > > COMPUTE B120=MEAN(V1 TO V11) . > COMPUTE B140=MEAN(V12 TO V21) . > COMPUTE B160=MEAN(V22 TO V31) . > COMPUTE B180=MEAN(V32 TO V41) . > COMPUTE B200=MEAN(V42 TO V51) . > COMPUTE B220=MEAN(V52 TO V61) . > COMPUTE B240=MEAN(V62 TO V72) . > COMPUTE B260=MEAN(V73 TO V82) . > COMPUTE B280=MEAN(V83 TO V92) . > COMPUTE B300=MEAN(V93 TO V102) . > COMPUTE B320=MEAN(V103 TO V112) . > COMPUTE B340=MEAN(V113 TO V122) . > COMPUTE B360=MEAN(V123 TO V133) . > COMPUTE B380=MEAN(V134 TO V143) . > COMPUTE B400=MEAN(V144 TO V153) . > COMPUTE B420=MEAN(V154 TO V163) . > COMPUTE B440=MEAN(V164 TO V173) . > COMPUTE B460=MEAN(V174 TO V183) . > COMPUTE B480=MEAN(V184 TO V194) . > COMPUTE B500=MEAN(V195 TO V204) . > COMPUTE B520=MEAN(V205 TO V214) . > COMPUTE B540=MEAN(V215 TO V224) . > COMPUTE B560=MEAN(V225 TO V234) . > COMPUTE B580=MEAN(V235 TO V245) . > COMPUTE B600=MEAN(V246 TO V255) . > COMPUTE B620=MEAN(V256 TO V265) . > COMPUTE B640=MEAN(V266 TO V275) . > COMPUTE B660=MEAN(V276 TO V285) . > COMPUTE B680=MEAN(V286 TO V295) . > COMPUTE B700=MEAN(V296 TO V306) . > COMPUTE B720=MEAN(V307 TO V316) . > COMPUTE B740=MEAN(V317 TO V326) . > COMPUTE B760=MEAN(V327 TO V336) . > COMPUTE B780=MEAN(V337 TO V346) . > COMPUTE B800=MEAN(V347 TO V356) . > COMPUTE B820=MEAN(V357 TO V367) . > COMPUTE B840=MEAN(V368 TO V377) . > COMPUTE B860=MEAN(V378 TO V387) . > COMPUTE B880=MEAN(V388 TO V397) . > COMPUTE B900=MEAN(V398 TO V407) . > COMPUTE B920=MEAN(V408 TO V417) . > COMPUTE B940=MEAN(V418 TO V428) . > COMPUTE B960=MEAN(V429 TO V438) . > > FLIP > VARIABLES=B120 TO B960 . > > DATASET CLOSE Raw. > > DELETE VARIABLES CASE_LBL. > > BEGIN PROGRAM. > import spss > c = spss.GetVariableCount() > v0 = spss.GetVariableName(0) > vn = spss.GetVariableName(c-1) > mean = "COMPUTE MEAN = MEAN(%(v0)s TO %(vn)s)" % locals() > stderr = "COMPUTE STDERR = SD(%(v0)s TO %(vn)s)/SQRT(%(c)s)" % locals() > dele = "DELETE VARIABLES %(v0)s TO %(vn)s" % locals() > spss.Submit(mean) > spss.Submit(stderr) > spss.Submit("EXECUTE.") > spss.Submit(dele) > END PROGRAM. > > FLIP > VARIABLES=ALL. > > WRITE OUTFILE=!CONCAT("'C:\out\",!outfile,"'") > /ALL. > EXECUTE. > > !DOEND > !DOEND > !DOEND > !DOEND > !DOEND > !ENDDEFINE. > > mainsub VLIST1 (009 016 022 047 099) VLIST2 (v t dw) VLIST3 (in ms un) > VLIST4 (parsopercularis parstriangularis lateralorbitofrontal > superiortemporal supramarginal superiorfrontal rostralmiddlefrontal > caudalmiddlefrontal parsorbitalis angular_gyrus) > VLIST5 (lh rh). ===================== 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 |
|
Without digging into the macro deeply, it is surely the case that that functionality could be implemented in Python. Think of writing a Python function whose parameters are the equivalent of the macro parameters. Then the macro can be translated pretty directly. It could be tuned further after that.
HTH, Jon Peck -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Oliver, Richard Sent: Thursday, August 28, 2008 5:37 AM To: [hidden email] Subject: Re: [SPSSX-L] UPDATED: Running PROGRAM>... Turn it around: Can what the macro is doing be done in Python instead? I'm not sure what the macro is doing, so I can't answer that question. ________________________________ From: SPSSX(r) Discussion on behalf of Greg Chulsky Sent: Thu 8/28/2008 12:00 AM To: [hidden email] Subject: Re: UPDATED: Running PROGRAM>... Ouch! Thank you. I didn't catch that. Is there any way to circumvent that problem? The program block needs to be repeated in every iteration of the loop, and what it does cannot be done with syntax alone. Oliver, Richard wrote: > You have a Python program block inside a Define-!Enddefine macro definition. That won't work. According to the SPSS Help: > > Program blocks cannot be contained within DEFINE-!ENDDEFINE macro definitions. > > ________________________________ > > From: SPSSX(r) Discussion on behalf of Greg Chulsky > Sent: Wed 8/27/2008 7:46 PM > To: [hidden email] > Subject: UPDATED: Running PROGRAM>... > > > > Because I've already received requests to see the actual code, I am > pasting my previous message along with the full code at the end. > > ---- > I am writing a syntax file that, when run, reads in files, does some > processing, and "spits out" new files. The processing includes a short > piece of Python code. Initially, the syntax I wrote did this only for > one file, and then I created a macro with loops (with the help of some > very helpful people on this mailing list) to make it repeat the process > for over 1,000 files. > > Before the loops, the syntax would run very quickly. As it ran, at the > bottom of each window, it would tell me what exactly it was doing at > that moment (e.g. Running COMPUTE, Running EXECUTE, Running BEGIN > PROGRAM, etc). > > Now I have added the loops and am trying to run it; for the first few > minutes, the text on the bottom reads "Running DEFINE". This makes > sense to me, as it is parsing a LOT of lines. The next thing that > appears for any significant length of time is "Running PROGRAM>...", and > at this point, it appears to freeze. It does not matter how long I > wait; it does not come out of this state. This was not a message that > ever appeared before the loops. The output window shows no errors. > > Does anybody know what could be wrong? Thank you in advance! > > -Greg > ---- > > DEFINE listvars() > !DO !v=1 !TO 440 > !LET !nam=!CONCAT("V",!v," F9.7") > !nam > !DOEND > !ENDDEFINE. > > DEFINE mainsub (VLIST1=!ENCLOSE('(',')') / VLIST2=!ENCLOSE('(',')') / > VLIST3=!ENCLOSE('(',')') / VLIST4=!ENCLOSE('(',')') / > VLIST5=!ENCLOSE('(',')')) > !DO !sub !IN (!VLIST1) > !DO !trg !IN (!VLIST2) > !DO !con !IN (!VLIST3) > !DO !roi !IN (!VLIST4) > !DO !hemi !IN (!VLIST5) > > !LET !file=!CONCAT("sub",!sub,"_",!trg,"_",!con,"_",!roi,"_",!hemi) > !LET !amp=!CONCAT(!file,".amp") > !LET !outfile=!CONCAT(!file,".txt") > > GET DATA /TYPE = TXT > /FILE = !CONCAT("'C:\amp\",!amp,"'") > /DELCASE = LINE > /DELIMITERS = " " > /ARRANGEMENT = DELIMITED > /FIRSTCASE = 2 > /IMPORTCASE = ALL > /VARIABLES = listvars > > CACHE. > DATASET NAME Raw. > > COMPUTE B120=MEAN(V1 TO V11) . > COMPUTE B140=MEAN(V12 TO V21) . > COMPUTE B160=MEAN(V22 TO V31) . > COMPUTE B180=MEAN(V32 TO V41) . > COMPUTE B200=MEAN(V42 TO V51) . > COMPUTE B220=MEAN(V52 TO V61) . > COMPUTE B240=MEAN(V62 TO V72) . > COMPUTE B260=MEAN(V73 TO V82) . > COMPUTE B280=MEAN(V83 TO V92) . > COMPUTE B300=MEAN(V93 TO V102) . > COMPUTE B320=MEAN(V103 TO V112) . > COMPUTE B340=MEAN(V113 TO V122) . > COMPUTE B360=MEAN(V123 TO V133) . > COMPUTE B380=MEAN(V134 TO V143) . > COMPUTE B400=MEAN(V144 TO V153) . > COMPUTE B420=MEAN(V154 TO V163) . > COMPUTE B440=MEAN(V164 TO V173) . > COMPUTE B460=MEAN(V174 TO V183) . > COMPUTE B480=MEAN(V184 TO V194) . > COMPUTE B500=MEAN(V195 TO V204) . > COMPUTE B520=MEAN(V205 TO V214) . > COMPUTE B540=MEAN(V215 TO V224) . > COMPUTE B560=MEAN(V225 TO V234) . > COMPUTE B580=MEAN(V235 TO V245) . > COMPUTE B600=MEAN(V246 TO V255) . > COMPUTE B620=MEAN(V256 TO V265) . > COMPUTE B640=MEAN(V266 TO V275) . > COMPUTE B660=MEAN(V276 TO V285) . > COMPUTE B680=MEAN(V286 TO V295) . > COMPUTE B700=MEAN(V296 TO V306) . > COMPUTE B720=MEAN(V307 TO V316) . > COMPUTE B740=MEAN(V317 TO V326) . > COMPUTE B760=MEAN(V327 TO V336) . > COMPUTE B780=MEAN(V337 TO V346) . > COMPUTE B800=MEAN(V347 TO V356) . > COMPUTE B820=MEAN(V357 TO V367) . > COMPUTE B840=MEAN(V368 TO V377) . > COMPUTE B860=MEAN(V378 TO V387) . > COMPUTE B880=MEAN(V388 TO V397) . > COMPUTE B900=MEAN(V398 TO V407) . > COMPUTE B920=MEAN(V408 TO V417) . > COMPUTE B940=MEAN(V418 TO V428) . > COMPUTE B960=MEAN(V429 TO V438) . > > FLIP > VARIABLES=B120 TO B960 . > > DATASET CLOSE Raw. > > DELETE VARIABLES CASE_LBL. > > BEGIN PROGRAM. > import spss > c = spss.GetVariableCount() > v0 = spss.GetVariableName(0) > vn = spss.GetVariableName(c-1) > mean = "COMPUTE MEAN = MEAN(%(v0)s TO %(vn)s)" % locals() > stderr = "COMPUTE STDERR = SD(%(v0)s TO %(vn)s)/SQRT(%(c)s)" % locals() > dele = "DELETE VARIABLES %(v0)s TO %(vn)s" % locals() > spss.Submit(mean) > spss.Submit(stderr) > spss.Submit("EXECUTE.") > spss.Submit(dele) > END PROGRAM. > > FLIP > VARIABLES=ALL. > > WRITE OUTFILE=!CONCAT("'C:\out\",!outfile,"'") > /ALL. > EXECUTE. > > !DOEND > !DOEND > !DOEND > !DOEND > !DOEND > !ENDDEFINE. > > mainsub VLIST1 (009 016 022 047 099) VLIST2 (v t dw) VLIST3 (in ms un) > VLIST4 (parsopercularis parstriangularis lateralorbitofrontal > superiortemporal supramarginal superiorfrontal rostralmiddlefrontal > caudalmiddlefrontal parsorbitalis angular_gyrus) > VLIST5 (lh rh). ===================== 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 ===================== 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 |
|
Thanks to everyone who helped me with this--especially Bob Walker and
Albert-Jan Roskam. Mr. Roskam helped me to Pythonify all the code; Mr. Walker came from a completely different angle, removing every vestige of Python from the code. I'd like to share Mr. Walker's code for the part of the program where I need to get a mean and standard error of a number of variables which is different in every case. I couldn't find a way to do it with syntax, and Jon Peck had formerly helped me write a Python script for it; Mr. Walker found the syntax soultion: COMPUTE VAR99999 = 0. RECODE VAR99999 (0=SYSMIS). COMPUTE MEANVAL = MEAN (VAR001 TO VAR99999). COMPUTE SDVAL = SD (VAR001 TO VAR99999). COUNT BASEVAL=VAR001 TO VAR99999 (LO THRU 999). COMPUTE STDERR = SDVAL / SQRT(BASEVAL). Depending on the nature of the data, others may need a different upper limit for the COUNT command. -Greg Peck, Jon wrote: > Without digging into the macro deeply, it is surely the case that that functionality could be implemented in Python. Think of writing a Python function whose parameters are the equivalent of the macro parameters. Then the macro can be translated pretty directly. It could be tuned further after that. > > HTH, > Jon Peck > > -----Original Message----- > From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Oliver, Richard > Sent: Thursday, August 28, 2008 5:37 AM > To: [hidden email] > Subject: Re: [SPSSX-L] UPDATED: Running PROGRAM>... > > Turn it around: Can what the macro is doing be done in Python instead? I'm not sure what the macro is doing, so I can't answer that question. > > ________________________________ > > From: SPSSX(r) Discussion on behalf of Greg Chulsky > Sent: Thu 8/28/2008 12:00 AM > To: [hidden email] > Subject: Re: UPDATED: Running PROGRAM>... > > > > Ouch! Thank you. I didn't catch that. Is there any way to circumvent > that problem? The program block needs to be repeated in every iteration > of the loop, and what it does cannot be done with syntax alone. > > Oliver, Richard wrote: > >> You have a Python program block inside a Define-!Enddefine macro definition. That won't work. According to the SPSS Help: >> >> Program blocks cannot be contained within DEFINE-!ENDDEFINE macro definitions. >> >> ________________________________ >> >> From: SPSSX(r) Discussion on behalf of Greg Chulsky >> Sent: Wed 8/27/2008 7:46 PM >> To: [hidden email] >> Subject: UPDATED: Running PROGRAM>... >> >> >> >> Because I've already received requests to see the actual code, I am >> pasting my previous message along with the full code at the end. >> >> ---- >> I am writing a syntax file that, when run, reads in files, does some >> processing, and "spits out" new files. The processing includes a short >> piece of Python code. Initially, the syntax I wrote did this only for >> one file, and then I created a macro with loops (with the help of some >> very helpful people on this mailing list) to make it repeat the process >> for over 1,000 files. >> >> Before the loops, the syntax would run very quickly. As it ran, at the >> bottom of each window, it would tell me what exactly it was doing at >> that moment (e.g. Running COMPUTE, Running EXECUTE, Running BEGIN >> PROGRAM, etc). >> >> Now I have added the loops and am trying to run it; for the first few >> minutes, the text on the bottom reads "Running DEFINE". This makes >> sense to me, as it is parsing a LOT of lines. The next thing that >> appears for any significant length of time is "Running PROGRAM>...", and >> at this point, it appears to freeze. It does not matter how long I >> wait; it does not come out of this state. This was not a message that >> ever appeared before the loops. The output window shows no errors. >> >> Does anybody know what could be wrong? Thank you in advance! >> >> -Greg >> ---- >> >> DEFINE listvars() >> !DO !v=1 !TO 440 >> !LET !nam=!CONCAT("V",!v," F9.7") >> !nam >> !DOEND >> !ENDDEFINE. >> >> DEFINE mainsub (VLIST1=!ENCLOSE('(',')') / VLIST2=!ENCLOSE('(',')') / >> VLIST3=!ENCLOSE('(',')') / VLIST4=!ENCLOSE('(',')') / >> VLIST5=!ENCLOSE('(',')')) >> !DO !sub !IN (!VLIST1) >> !DO !trg !IN (!VLIST2) >> !DO !con !IN (!VLIST3) >> !DO !roi !IN (!VLIST4) >> !DO !hemi !IN (!VLIST5) >> >> !LET !file=!CONCAT("sub",!sub,"_",!trg,"_",!con,"_",!roi,"_",!hemi) >> !LET !amp=!CONCAT(!file,".amp") >> !LET !outfile=!CONCAT(!file,".txt") >> >> GET DATA /TYPE = TXT >> /FILE = !CONCAT("'C:\amp\",!amp,"'") >> /DELCASE = LINE >> /DELIMITERS = " " >> /ARRANGEMENT = DELIMITED >> /FIRSTCASE = 2 >> /IMPORTCASE = ALL >> /VARIABLES = listvars >> >> CACHE. >> DATASET NAME Raw. >> >> COMPUTE B120=MEAN(V1 TO V11) . >> COMPUTE B140=MEAN(V12 TO V21) . >> COMPUTE B160=MEAN(V22 TO V31) . >> COMPUTE B180=MEAN(V32 TO V41) . >> COMPUTE B200=MEAN(V42 TO V51) . >> COMPUTE B220=MEAN(V52 TO V61) . >> COMPUTE B240=MEAN(V62 TO V72) . >> COMPUTE B260=MEAN(V73 TO V82) . >> COMPUTE B280=MEAN(V83 TO V92) . >> COMPUTE B300=MEAN(V93 TO V102) . >> COMPUTE B320=MEAN(V103 TO V112) . >> COMPUTE B340=MEAN(V113 TO V122) . >> COMPUTE B360=MEAN(V123 TO V133) . >> COMPUTE B380=MEAN(V134 TO V143) . >> COMPUTE B400=MEAN(V144 TO V153) . >> COMPUTE B420=MEAN(V154 TO V163) . >> COMPUTE B440=MEAN(V164 TO V173) . >> COMPUTE B460=MEAN(V174 TO V183) . >> COMPUTE B480=MEAN(V184 TO V194) . >> COMPUTE B500=MEAN(V195 TO V204) . >> COMPUTE B520=MEAN(V205 TO V214) . >> COMPUTE B540=MEAN(V215 TO V224) . >> COMPUTE B560=MEAN(V225 TO V234) . >> COMPUTE B580=MEAN(V235 TO V245) . >> COMPUTE B600=MEAN(V246 TO V255) . >> COMPUTE B620=MEAN(V256 TO V265) . >> COMPUTE B640=MEAN(V266 TO V275) . >> COMPUTE B660=MEAN(V276 TO V285) . >> COMPUTE B680=MEAN(V286 TO V295) . >> COMPUTE B700=MEAN(V296 TO V306) . >> COMPUTE B720=MEAN(V307 TO V316) . >> COMPUTE B740=MEAN(V317 TO V326) . >> COMPUTE B760=MEAN(V327 TO V336) . >> COMPUTE B780=MEAN(V337 TO V346) . >> COMPUTE B800=MEAN(V347 TO V356) . >> COMPUTE B820=MEAN(V357 TO V367) . >> COMPUTE B840=MEAN(V368 TO V377) . >> COMPUTE B860=MEAN(V378 TO V387) . >> COMPUTE B880=MEAN(V388 TO V397) . >> COMPUTE B900=MEAN(V398 TO V407) . >> COMPUTE B920=MEAN(V408 TO V417) . >> COMPUTE B940=MEAN(V418 TO V428) . >> COMPUTE B960=MEAN(V429 TO V438) . >> >> FLIP >> VARIABLES=B120 TO B960 . >> >> DATASET CLOSE Raw. >> >> DELETE VARIABLES CASE_LBL. >> >> BEGIN PROGRAM. >> import spss >> c = spss.GetVariableCount() >> v0 = spss.GetVariableName(0) >> vn = spss.GetVariableName(c-1) >> mean = "COMPUTE MEAN = MEAN(%(v0)s TO %(vn)s)" % locals() >> stderr = "COMPUTE STDERR = SD(%(v0)s TO %(vn)s)/SQRT(%(c)s)" % locals() >> dele = "DELETE VARIABLES %(v0)s TO %(vn)s" % locals() >> spss.Submit(mean) >> spss.Submit(stderr) >> spss.Submit("EXECUTE.") >> spss.Submit(dele) >> END PROGRAM. >> >> FLIP >> VARIABLES=ALL. >> >> WRITE OUTFILE=!CONCAT("'C:\out\",!outfile,"'") >> /ALL. >> EXECUTE. >> >> !DOEND >> !DOEND >> !DOEND >> !DOEND >> !DOEND >> !ENDDEFINE. >> >> mainsub VLIST1 (009 016 022 047 099) VLIST2 (v t dw) VLIST3 (in ms un) >> VLIST4 (parsopercularis parstriangularis lateralorbitofrontal >> superiortemporal supramarginal superiorfrontal rostralmiddlefrontal >> caudalmiddlefrontal parsorbitalis angular_gyrus) >> VLIST5 (lh rh). >> > > ===================== > 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 > > ===================== > 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 |
| Free forum by Nabble | Edit this page |
