|
How should lists in loops be delimited?
When I try !DO !sub !IN ("009" "016" "022" "047" "099") I get Error # 6834 In a macro expression, an operand was not preceded by an operator. Whereas when I try !DO !sub !IN ("009","016","022","047","099") I get Error # 6845 In a macro expression, there is a comma which is not part of a function argument list. ===================== 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 |
|
Greg,
The delimiter depends upon how you've chosen to set up your macro. You do not need quotations if you are iterating over a series of values, such as a list of names. Here's a snippet that may help: DEFINE !GLOBAL(VLIST=!ENCLOSE('(',')')). !DO !Z !IN (!VLIST). [STATEMENTS OR MACRO COMMANDS] !DOEND. !ENDDEFINE. * CALL MACRO AND IDENTIFY VARIABLES. !GLOBAL VLIST (FRANCE GERMANY ITALY). You can use macro commands without first using DEFINE-END DEFINE to establish that it is a macro. HTH, Bob Walker Surveys & Forecasts, LLC <http://www.safllc.com> www.safllc.com _____ From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Greg Chulsky Sent: Monday, August 25, 2008 5:25 PM To: [hidden email] Subject: Correct macro syntax for list-processing loops How should lists in loops be delimited? When I try !DO !sub !IN ("009" "016" "022" "047" "099") I get Error # 6834 In a macro expression, an operand was not preceded by an operator. Whereas when I try !DO !sub !IN ("009","016","022","047","099") I get Error # 6845 In a macro expression, there is a comma which is not part of a function argument list. ===================== 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 E-mail message checked by Spyware Doctor (6.0.0.362) Database version: 5.10550 http://www.pctools.com/spyware-doctor-antivirus/ <http://www.pctools.com/en/spyware-doctor-antivirus/> E-mail message checked by Spyware Doctor (6.0.0.362) Database version: 5.10550 http://www.pctools.com/en/spyware-doctor-antivirus/ ===================== 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 |
|
Hi Greg,
Identify each block of variables by using a keyword you assign; your list cannot appear in the !DO statement itself. The arguments for each variable are inserted once your macro is called. Yours might look like this: 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) [STATEMENTS AND COMMANDS] !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 caudalmi ddlefrontal parsorbitalis angular_gyrus) VLIST3 (lh rh). HTH, Bob Walker Surveys & Forecasts, LLC <http://www.safllc.com> www.safllc.com _____ From: Greg Chulsky [mailto:[hidden email]] Sent: Monday, August 25, 2008 6:52 PM To: Bob Walker Cc: [hidden email] Subject: Re: Correct macro syntax for list-processing loops Bob, Thank you for your help! I actually have a bunch of nested loops, which I'll paste at the bottom of what I'm typing now. I couldn't think of a way to expand any method with identifying variables when calling the macro to this. Is there one? I thought there would just be some delimiter I could put in there to make these loops work. -Greg [OTHER MACRO DEFINITIONS] DEFINE mainsub() !DO !sub !IN ("009","016","022","047","099") !DO !trg !IN ("v","t","dw") !DO !con !IN ("in","ms","un") !DO !roi !IN ("parsopercularis","parstriangularis","lateralorbitofrontal","supe riortemporal","supramarginal","superiorfrontal","rostralmiddlefrontal","caud almi ddlefrontal","parsorbitalis","angular_gyrus") !DO !hemi !IN ("lh","rh") [STATEMENTS AND COMMANDS] !DOEND !DOEND !DOEND !DOEND !DOEND !ENDDEFINE. mainsub. Bob Walker wrote: Greg, The delimiter depends upon how you've chosen to set up your macro. You do not need quotations if you are iterating over a series of values, such as a list of names. Here's a snippet that may help: DEFINE !GLOBAL(VLIST=!ENCLOSE('(',')')). !DO !Z !IN (!VLIST). [STATEMENTS OR MACRO COMMANDS] !DOEND. !ENDDEFINE. * CALL MACRO AND IDENTIFY VARIABLES. !GLOBAL VLIST (FRANCE GERMANY ITALY). You can use macro commands without first using DEFINE-END DEFINE to establish that it is a macro. HTH, Bob Walker Surveys & Forecasts, LLC <http://www.safllc.com> <http://www.safllc.com> www.safllc.com _____ From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Greg Chulsky Sent: Monday, August 25, 2008 5:25 PM To: [hidden email] Subject: Correct macro syntax for list-processing loops How should lists in loops be delimited? When I try !DO !sub !IN ("009" "016" "022" "047" "099") I get Error # 6834 In a macro expression, an operand was not preceded by an operator. Whereas when I try !DO !sub !IN ("009","016","022","047","099") I get Error # 6845 In a macro expression, there is a comma which is not part of a function argument list. E-mail message checked by Spyware Doctor (6.0.0.362) Database version: 5.10550 http://www.pctools.com/spyware-doctor-antivirus/ <http://www.pctools.com/en/spyware-doctor-antivirus/> E-mail message checked by Spyware Doctor (6.0.0.362) Database version: 5.10550 http://www.pctools.com/en/spyware-doctor-antivirus/ ===================== 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 Greg Chulsky
Hi Greg,
try something like this: !do !sub !in (!list) *'processing the list'* !doend where "!list" is a macro variable that should be fed with the list you need (the function argument list mentioned by the error). hth, Vlad On Tue, Aug 26, 2008 at 12:24 AM, Greg Chulsky <[hidden email]> wrote: > How should lists in loops be delimited? > > When I try > !DO !sub !IN ("009" "016" "022" "047" "099") > I get > Error # 6834 > In a macro expression, an operand was not preceded by an operator. > > Whereas when I try > !DO !sub !IN ("009","016","022","047","099") > I get > Error # 6845 > In a macro expression, there is a comma which is not part of a function > argument list. > ===================== 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 |
|
Hi Greg,
This is an alternative approach: * test data. data list free / x (a3). begin data 001 002 axx 010 end data. set mprint = on. * function ("macro") begin program. import spss def doin (mylist): for i in range(len(mylist)): spss.Submit(""" if (x = '%s') flag = 1. """ % (mylist[i])) doin (["001", "002", "0004", "010"]) end program. --- On Tue, 8/26/08, vlad simion <[hidden email]> wrote: > From: vlad simion <[hidden email]> > Subject: Re: Correct macro syntax for list-processing loops > To: [hidden email] > Date: Tuesday, August 26, 2008, 8:22 AM > Hi Greg, > > try something like this: > > !do !sub !in (!list) > *'processing the list'* > !doend > > where "!list" is a macro variable that should be > fed with the list you need > (the function argument list mentioned by the error). > > hth, > Vlad > > > > > On Tue, Aug 26, 2008 at 12:24 AM, Greg Chulsky > <[hidden email]> wrote: > > > How should lists in loops be delimited? > > > > When I try > > !DO !sub !IN ("009" "016" > "022" "047" "099") > > I get > > Error # 6834 > > In a macro expression, an operand was not preceded by > an operator. > > > > Whereas when I try > > !DO !sub !IN > ("009","016","022","047","099") > > I get > > Error # 6845 > > In a macro expression, there is a comma which is not > part of a function > > argument list. > > ===================== 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 |
