I have a macro that calls several files and create custom tables based on a
specific filter for each table. However, when the macro runs into a scenario where there are not cases that meet the filter criteria, instead of moving on to the next custom table, the process is halting. Can anyone provide suggestions on how to work around this? Thanks. ===================== 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 |
Dear Sandra,
It looks as if you didn't get any reply to your post yet. I tried to replicate your problem with some very basic test data but but I failed miserably (see code below). That is, after the warning that group 1 is empty, I get fine results for group 2. Could you please provide us with some more details (best case scenario your syntax + test data)? Thank you! Ruben ***Failing replication syntax. set mpr on seed 1. data list free/group. begin data 0 0 0 0 0 2 2 2 2 2 end data. compute v1=rv.ber(.5). define !freqs() !do !lv=0 !to 2 temp. select if group=!lv. title !con('This is the result for group = ',!lv). freq v1. !doend !enddefine. !freqs. > Date: Thu, 11 Nov 2010 12:21:37 -0500 > From: [hidden email] > Subject: Macro - No cases satisfy filter > To: [hidden email] > > I have a macro that calls several files and create custom tables based on a > specific filter for each table. However, when the macro runs into a > scenario where there are not cases that meet the filter criteria, instead > of moving on to the next custom table, the process is halting. > > Can anyone provide suggestions on how to work around this? > > Thanks. > > ===================== > 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 Sandra Lenga
Sandra,
This sloppy example generates a warning, but runs without halting... how is your code different? SET MPRINT OFF MEXPAND OFF. PRESERVE. SET MPRINT ON MEXPAND ON. DATASET CLOSE ALL. DATA LIST FREE /var1 to var10. BEGIN DATA 4,8,27,78,01,9,8,9,9,4 10,9,21,12,11,7,7,6,5,4 4,2,44,100,900,3,3,2,2,4 12,4,53,38,8,4,4,4,4,4 END DATA. DATASET NAME File_1 WINDOW=FRONT. DATASET COPY File_2 WINDOW=FRONT. DATASET COPY File_3 WINDOW=FRONT. * TO MAKE FILE2 HAVE NO QUALIFYING CASES. DATASET ACTIVATE File_2 WINDOW=FRONT. RECODE var1 (4=99). * TO MAKE FILE3 HAVE THREE QUALIFYING CASES. DATASET ACTIVATE File_3 WINDOW=FRONT. RECODE var1 (12=4). EXECUTE. DEFINE !EXAMPLE() !DO !Z = 1 !TO 3 DATASET ACTIVATE !CONCAT("File_",!Z). SELECT IF VAR1=4. CTABLES /TABLE VAR2 BY VAR1 [COUNT]. !DOEND DATASET CLOSE ALL. !ENDDEFINE. !EXAMPLE. RESTORE. Bob Walker Surveys & Forecasts, LLC www.safllc.com -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Sandra Lenga Sent: Thursday, November 11, 2010 12:22 PM To: [hidden email] Subject: Macro - No cases satisfy filter I have a macro that calls several files and create custom tables based on a specific filter for each table. However, when the macro runs into a scenario where there are not cases that meet the filter criteria, instead of moving on to the next custom table, the process is halting. Can anyone provide suggestions on how to work around this? Thanks. ===================== 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 Bob,
Thanks for getting back to me. This was a great example. Our code differs in that it is failing/halting when it does not find any cases that satisfy the filter_$=1. See sample syntax below:
GET FILE='C:\SampleData.sav'. SORT CASES BY var2. AGGREGATE /OUTFILE=* /BREAK=var2 /notused = N. WRITE OUTFILE='C:\temp.sps'
/'!SPLIT var=var2 value="' var2'".'. Execute. *set mprint=on. SET MPRINT OFF MEXPAND OFF. PRESERVE. SET MPRINT ON MEXPAND ON. DATASET CLOSE ALL. *//////////////////////////////////////////. DEFINE !SPLIT (var=!TOKENS(1) /value=!TOKENS(1)) SELECT IF (!var=!value). GET FILE=!QUOTE(!CONCAT('C:\SampleData_',!UNQUOTE(!value),'.sav')). USE ALL. COMPUTE filter_$=(MISSING(var3) and var4=2 and var8=1). VARIABLE LABEL filter_$ 'MISSING(var3) and var4=2 and'+ ' var8=1 (FILTER)'. VALUE LABELS filter_$ 0 'Not Selected' 1 'Selected'. FORMAT filter_$ (f1.0). EXECUTE . SELECT IF filter_$=1.
CTABLES /VLABELS VARIABLES=var5 var4 var6 var7 DISPLAY=DEFAULT /TABLE var4 > (var6 [COUNT F40.0] +var7 [COUNT F40.0]) BY var5 /CATEGORIES VARIABLES=var4 var7 ORDER=A KEY=VALUE EMPTY=EXCLUDE /CATEGORIES VARIABLES=var6 ORDER=A KEY=VALUE EMPTY=INCLUDE TOTAL=YES POSITION=AFTER. OUTPUT SAVE OUTFILE=!QUOTE(!CONCAT('C:\SampleData_',!UNQUOTE(!value),'.SPO')). OUTPUT CLOSE ALL. DATASET CLOSE ALL. !ENDDEFINE. *//////////////////////////////////////////. GET FILE='C:\SampleData.sav'.
INCLUDE 'C:\temp.sps'. This is actually the first time I have posted to the listserv. I hope this information is comprehensive enough.
Thanks again for your help.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Sandra Lenga Systems Integration Coordinator
Loudoun County Public Schools 21000 Education Court Ashburn, VA 20148 Voice: 571-252-1485 Fax: 571-252-1633 http://www.lcps.org Aspire to inspire before you expire.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Please Note Change in Email Address to lcps.org. >>> Bob Walker <[hidden email]> 11/15/2010 11:52 AM >>> Sandra, This sloppy example generates a warning, but runs without halting... how is your code different? SET MPRINT OFF MEXPAND OFF. PRESERVE. SET MPRINT ON MEXPAND ON. DATASET CLOSE ALL. DATA LIST FREE /var1 to var10. BEGIN DATA 4,8,27,78,01,9,8,9,9,4 10,9,21,12,11,7,7,6,5,4 4,2,44,100,900,3,3,2,2,4 12,4,53,38,8,4,4,4,4,4 END DATA. DATASET NAME File_1 WINDOW=FRONT. DATASET COPY File_2 WINDOW=FRONT. DATASET COPY File_3 WINDOW=FRONT. * TO MAKE FILE2 HAVE NO QUALIFYING CASES. DATASET ACTIVATE File_2 WINDOW=FRONT. RECODE var1 (4=99). * TO MAKE FILE3 HAVE THREE QUALIFYING CASES. DATASET ACTIVATE File_3 WINDOW=FRONT. RECODE var1 (12=4). EXECUTE. DEFINE !EXAMPLE() !DO !Z = 1 !TO 3 DATASET ACTIVATE !CONCAT("File_",!Z). SELECT IF VAR1=4. CTABLES /TABLE VAR2 BY VAR1 [COUNT]. !DOEND DATASET CLOSE ALL. !ENDDEFINE. !EXAMPLE. RESTORE. Bob Walker Surveys & Forecasts, LLC www.safllc.com -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Sandra Lenga Sent: Thursday, November 11, 2010 12:22 PM To: [hidden email] Subject: Macro - No cases satisfy filter I have a macro that calls several files and create custom tables based on a specific filter for each table. However, when the macro runs into a scenario where there are not cases that meet the filter criteria, instead of moving on to the next custom table, the process is halting. Can anyone provide suggestions on how to work around this? Thanks. ===================== 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 Ruben Geert van den Berg
Hi Ruben,
Thanks for your reply. Please see the following sample syntax. I hope it is clear.
Hi Bob,
Thanks for getting back to me. This was a great example. Our code differs in that it is failing/halting when it does not find any cases that satisfy the filter_$=1. See sample syntax below:
GET FILE='C:\SampleData.sav'. SORT CASES BY var2. AGGREGATE /OUTFILE=* /BREAK=var2 /notused = N. WRITE OUTFILE='C:\temp.sps'
/'!SPLIT var=var2 value="' var2'".'. Execute. *set mprint=on. SET MPRINT OFF MEXPAND OFF. PRESERVE. SET MPRINT ON MEXPAND ON. DATASET CLOSE ALL. *//////////////////////////////////////////. DEFINE !SPLIT (var=!TOKENS(1) /value=!TOKENS(1)) SELECT IF (!var=!value). GET FILE=!QUOTE(!CONCAT('C:\SampleData_',!UNQUOTE(!value),'.sav')). USE ALL. COMPUTE filter_$=(MISSING(var3) and var4=2 and var8=1). VARIABLE LABEL filter_$ 'MISSING(var3) and var4=2 and'+ ' var8=1 (FILTER)'. VALUE LABELS filter_$ 0 'Not Selected' 1 'Selected'. FORMAT filter_$ (f1.0). EXECUTE . SELECT IF filter_$=1.
CTABLES /VLABELS VARIABLES=var5 var4 var6 var7 DISPLAY=DEFAULT /TABLE var4 > (var6 [COUNT F40.0] +var7 [COUNT F40.0]) BY var5 /CATEGORIES VARIABLES=var4 var7 ORDER=A KEY=VALUE EMPTY=EXCLUDE /CATEGORIES VARIABLES=var6 ORDER=A KEY=VALUE EMPTY=INCLUDE TOTAL=YES POSITION=AFTER. OUTPUT SAVE OUTFILE=!QUOTE(!CONCAT('C:\SampleData_',!UNQUOTE(!value),'.SPO')). OUTPUT CLOSE ALL. DATASET CLOSE ALL. !ENDDEFINE. *//////////////////////////////////////////. GET FILE='C:\SampleData.sav'.
INCLUDE 'C:\temp.sps'. This is actually the first time I have posted to the listserv. I hope this information is comprehensive enough.
Thanks again for your help.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Sandra Lenga Systems Integration Coordinator
Loudoun County Public Schools 21000 Education Court Ashburn, VA 20148 Voice: 571-252-1485 Fax: 571-252-1633 http://www.lcps.org Aspire to inspire before you expire.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Please Note Change in Email Address to lcps.org. >>> Ruben van den Berg <[hidden email]> 11/12/2010 3:15 PM >>> Dear Sandra, It looks as if you didn't get any reply to your post yet. I tried to replicate your problem with some very basic test data but but I failed miserably (see code below). That is, after the warning that group 1 is empty, I get fine results for group 2.
Could you please provide us with some more details (best case scenario your syntax + test data)?
Thank you!
Ruben
***Failing replication syntax.
set mpr on seed 1.
data list free/group.
begin data
0 0 0 0 0 2 2 2 2 2
end data.
compute v1=rv.ber(.5).
define !freqs()
!do !lv=0 !to 2
temp.
select if group=!lv.
title !con('This is the result for group = ',!lv).
freq v1.
!doend
!enddefine.
!freqs. > Date: Thu, 11 Nov 2010 12:21:37 -0500 > From: [hidden email] > Subject: Macro - No cases satisfy filter > To: [hidden email] > > I have a macro that calls several files and create custom tables based on a > specific filter for each table. However, when the macro runs into a > scenario where there are not cases that meet the filter criteria, instead > of moving on to the next custom table, the process is halting. > > Can anyone provide suggestions on how to work around this? > > Thanks. > > ===================== > 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 |
Dear Sandra,
Your syntax looks rather unusual and contains a number of oddities. -The data files called in the macro (e.g. SampleData_1.sav) are not created in the syntax below. -The filter syntax is typically pasted from the menu rather than typed and the combination of this block with 'select if' seems a bit far fetched (you'd normally incorporate the selection conditions directly into a 'select if' statement). -The second line of the 'write outfile' command contains double quotes that should not be there. -Usually, 'insert' is used instead of 'include'. One of the reasons is that 'insert' carries out everything it can when an error occurs while 'include' breaks down and stops altogether in this case. I think it may be a better idea to rewrite the syntax from scratch and base it upon a temp. select if (...). construction. We'd obviously like to help you if necessary but (for me at least) the desired result (rather than the approach used so far) should be described more clearly than I can make up from your syntax. Best regards, Ruben Date: Tue, 16 Nov 2010 16:07:24 -0500 From: [hidden email] Subject: Re: Macro - No cases satisfy filter To: [hidden email] Hi Ruben,
Thanks for your reply. Please see the following sample syntax. I hope it is clear.
Hi Bob,
Thanks for getting back to me. This was a great example. Our code differs in that it is failing/halting when it does not find any cases that satisfy the filter_$=1. See sample syntax below:
GET FILE='C:\SampleData.sav'. SORT CASES BY var2. AGGREGATE /OUTFILE=* /BREAK=var2 /notused = N. WRITE OUTFILE='C:\temp.sps'
/'!SPLIT var=var2 value="' var2'".'. Execute. *set mprint=on. SET MPRINT OFF MEXPAND OFF. PRESERVE. SET MPRINT ON MEXPAND ON. DATASET CLOSE ALL. *//////////////////////////////////////////. DEFINE !SPLIT (var=!TOKENS(1) /value=!TOKENS(1)) SELECT IF (!var=!value). GET FILE=!QUOTE(!CONCAT('C:\SampleData_',!UNQUOTE(!value),'.sav')). USE ALL. COMPUTE filter_$=(MISSING(var3) and var4=2 and var8=1). VARIABLE LABEL filter_$ 'MISSING(var3) and var4=2 and'+ ' var8=1 (FILTER)'. VALUE LABELS filter_$ 0 'Not Selected' 1 'Selected'. FORMAT filter_$ (f1.0). EXECUTE . SELECT IF filter_$=1.
CTABLES /VLABELS VARIABLES=var5 var4 var6 var7 DISPLAY=DEFAULT /TABLE var4 > (var6 [COUNT F40.0] +var7 [COUNT F40.0]) BY var5 /CATEGORIES VARIABLES=var4 var7 ORDER=A KEY=VALUE EMPTY=EXCLUDE /CATEGORIES VARIABLES=var6 ORDER=A KEY=VALUE EMPTY=INCLUDE TOTAL=YES POSITION=AFTER. OUTPUT SAVE OUTFILE=!QUOTE(!CONCAT('C:\SampleData_',!UNQUOTE(!value),'.SPO')). OUTPUT CLOSE ALL. DATASET CLOSE ALL. !ENDDEFINE. *//////////////////////////////////////////. GET FILE='C:\SampleData.sav'.
INCLUDE 'C:\temp.sps'. This is actually the first time I have posted to the listserv. I hope this information is comprehensive enough.
Thanks again for your help.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Sandra Lenga Systems Integration Coordinator
Loudoun County Public Schools 21000 Education Court Ashburn, VA 20148 Voice: 571-252-1485 Fax: 571-252-1633 http://www.lcps.org Aspire to inspire before you expire.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Please Note Change in Email Address to lcps.org. >>> Ruben van den Berg <[hidden email]> 11/12/2010 3:15 PM >>> Dear Sandra, It looks as if you didn't get any reply to your post yet. I tried to replicate your problem with some very basic test data but but I failed miserably (see code below). That is, after the warning that group 1 is empty, I get fine results for group 2.
Could you please provide us with some more details (best case scenario your syntax + test data)?
Thank you!
Ruben
***Failing replication syntax.
set mpr on seed 1.
data list free/group.
begin data
0 0 0 0 0 2 2 2 2 2
end data.
compute v1=rv.ber(.5).
define !freqs()
!do !lv=0 !to 2
temp.
select if group=!lv.
title !con('This is the result for group = ',!lv).
freq v1.
!doend
!enddefine.
!freqs. > Date: Thu, 11 Nov 2010 12:21:37 -0500 > From: [hidden email] > Subject: Macro - No cases satisfy filter > To: [hidden email] > > I have a macro that calls several files and create custom tables based on a > specific filter for each table. However, when the macro runs into a > scenario where there are not cases that meet the filter criteria, instead > of moving on to the next custom table, the process is halting. > > Can anyone provide suggestions on how to work around this? > > Thanks. > > ===================== > 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 |
Sandra, Ruben is right… it would help us if you could explain what it is you are trying to do, and the file names you’re using, and then we could help you a bit more. It looks like you went to Raynald’s site and clipped some code not knowing exactly what it does. Macros can be very confusing… From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Ruben van den Berg Dear Sandra, Your syntax looks rather unusual and contains a number of oddities. -The data files called in the macro (e.g. SampleData_1.sav) are not created in the syntax below. -The filter syntax is typically pasted from the menu rather than typed and the combination of this block with 'select if' seems a bit far fetched (you'd normally incorporate the selection conditions directly into a 'select if' statement). -The second line of the 'write outfile' command contains double quotes that should not be there. -Usually, 'insert' is used instead of 'include'. One of the reasons is that 'insert' carries out everything it can when an error occurs while 'include' breaks down and stops altogether in this case. I think it may be a better idea to rewrite the syntax from scratch and base it upon a temp. select if (...). construction. We'd obviously like to help you if necessary but (for me at least) the desired result (rather than the approach used so far) should be described more clearly than I can make up from your syntax. Best regards, Ruben Date: Tue, 16 Nov 2010 16:07:24 -0500 Hi Ruben, Thanks for your reply. Please see the following sample syntax. I hope it is clear. Hi Bob, Thanks for getting back to me. This was a great example. Our code differs in that it is failing/halting when it does not find any cases that satisfy the filter_$=1. See sample syntax below:
WRITE OUTFILE='C:\temp.sps'
SELECT IF filter_$=1.
GET FILE='C:\SampleData.sav'. This is actually the first time I have posted to the listserv. I hope this information is comprehensive enough. Thanks again for your help. >>>>>>>>>>>>>>>>>>>>>>>>>>>> Systems Integration Coordinator Aspire to inspire before you expire. >>>>>>>>>>>>>>>>>>>>>>>>>>>> Please Note Change in Email Address to lcps.org.
It looks as if you didn't get any reply to your post yet. I tried to replicate your problem with some very basic test data but but I failed miserably (see code below). That is, after the warning that group 1 is empty, I get fine results for group 2. Could you please provide us with some more details (best case scenario your syntax + test data)? Thank you! Ruben ***Failing replication syntax. set mpr on seed 1. data list free/group. begin data 0 0 0 0 0 2 2 2 2 2 end data. compute v1=rv.ber(.5). define !freqs() !do !lv=0 !to 2 temp. select if group=!lv. title !con('This is the result for group = ',!lv). freq v1. !doend !enddefine. !freqs.
|
Free forum by Nabble | Edit this page |