Forcing a failure in batch mode.

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Forcing a failure in batch mode.

janetB

Hi

I need a way to force a failure in batch mode if certain conditions aren't met so the code will stop.

The code below doesn't work but hopefully explains the concept.

               If TotCount gt 3000 counter1 =1.

               If Agency1Count gt 2500 counter2 =1.

               If Agency2Count gt 500 counter3=1.

               Compute ShowStopper = counter1+counter2+counter3.

 

In case any of the values added are null I would like the code to throw an error since it can't add nulls.

I think this worked in earlier versions of SPSS, but either I am remembering wrong or SPSS has changed its handling of nulls.

Either way, I need all 3 conditions to be true or an error (not a warning) to be thrown. I am using SPSS 22.

 

Any help would be greatly appreciated.

 

Janet

===================== 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
Reply | Threaded
Open this post in threaded view
|

Re: Forcing a failure in batch mode.

Jon Peck
I presume that by null, you mean sysmis in statistics.  Arithmetic with sysmis does not raise an error.  It just causes the result to be sysmis.

The INSERT command provides the ERROR keyword which can be set to CONTINUE (the default) or STOP.  (INSERT EXEC provides the ability to run alternative code in case of an error).

But you need to generate an error, not just a warning such as you would get from division by 0 or detect the condition some other way

So you could do something like this

 Compute ShowStopper = counter1+counter2+counter3.  
do if sysmis(ShowStopper).
    print outfile="t:/temp/error.txt' /$casenum.
end if.
where the outfile location is invalid (I have no t drive).

Ugly, but it would generate an error on that condition.  If you wrap this in an INSERT with ERROR=STOP, it should stop Statistics in its tracks.



On Wed, Mar 11, 2020 at 11:53 AM Biblin, Janet, ACBH <[hidden email]> wrote:

Hi

I need a way to force a failure in batch mode if certain conditions aren't met so the code will stop.

The code below doesn't work but hopefully explains the concept.

               If TotCount gt 3000 counter1 =1.

               If Agency1Count gt 2500 counter2 =1.

               If Agency2Count gt 500 counter3=1.

               Compute ShowStopper = counter1+counter2+counter3.

 

In case any of the values added are null I would like the code to throw an error since it can't add nulls.

I think this worked in earlier versions of SPSS, but either I am remembering wrong or SPSS has changed its handling of nulls.

Either way, I need all 3 conditions to be true or an error (not a warning) to be thrown. I am using SPSS 22.

 

Any help would be greatly appreciated.

 

Janet

===================== 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


--
Jon K Peck
[hidden email]

===================== 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
Reply | Threaded
Open this post in threaded view
|

Re: Forcing a failure in batch mode.

janetB

Thanks for helping. Unfortunately, it’s generating the error whether or not the condition in the “do if” is met.

Is there some way to control this?

(I also tried the TEMP command with the same results – it balked even when the temp condition wasn’t met. )

 

From: Jon Peck <[hidden email]>
Sent: Wednesday, March 11, 2020 2:36 PM
To: Biblin, Janet, ACBH <[hidden email]>
Cc: SPSS List <[hidden email]>
Subject: Re: [SPSSX-L] Forcing a failure in batch mode.

 

I presume that by null, you mean sysmis in statistics.  Arithmetic with sysmis does not raise an error.  It just causes the result to be sysmis.

 

The INSERT command provides the ERROR keyword which can be set to CONTINUE (the default) or STOP.  (INSERT EXEC provides the ability to run alternative code in case of an error).

 

But you need to generate an error, not just a warning such as you would get from division by 0 or detect the condition some other way

 

So you could do something like this

 

 Compute ShowStopper = counter1+counter2+counter3.  

do if sysmis(ShowStopper).

    print outfile="t:/temp/error.txt' /$casenum.
end if.

where the outfile location is invalid (I have no t drive).

 

Ugly, but it would generate an error on that condition.  If you wrap this in an INSERT with ERROR=STOP, it should stop Statistics in its tracks.

 

 

 

On Wed, Mar 11, 2020 at 11:53 AM Biblin, Janet, ACBH <[hidden email]> wrote:

Hi

I need a way to force a failure in batch mode if certain conditions aren't met so the code will stop.

The code below doesn't work but hopefully explains the concept.

               If TotCount gt 3000 counter1 =1.

               If Agency1Count gt 2500 counter2 =1.

               If Agency2Count gt 500 counter3=1.

               Compute ShowStopper = counter1+counter2+counter3.

 

In case any of the values added are null I would like the code to throw an error since it can't add nulls.

I think this worked in earlier versions of SPSS, but either I am remembering wrong or SPSS has changed its handling of nulls.

Either way, I need all 3 conditions to be true or an error (not a warning) to be thrown. I am using SPSS 22.

 

Any help would be greatly appreciated.

 

Janet

===================== 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


 

--

Jon K Peck
[hidden email]

** This email was sent from an external source. If you do not know the sender, do not click on links or attachments. **

 

===================== 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
Reply | Threaded
Open this post in threaded view
|

Re: Forcing a failure in batch mode.

Jon Peck
I guess the parer is too diligent.  That leaves Python as a solution.  You would have to detect a sysmis value after the data pass using, say, AGGREGATE, and then a little Python block that would inspect that and either run the rest of the syntax via INSERT or similar or stop.

On Wed, Mar 11, 2020 at 5:10 PM Biblin, Janet, ACBH <[hidden email]> wrote:

Thanks for helping. Unfortunately, it’s generating the error whether or not the condition in the “do if” is met.

Is there some way to control this?

(I also tried the TEMP command with the same results – it balked even when the temp condition wasn’t met. )

 

From: Jon Peck <[hidden email]>
Sent: Wednesday, March 11, 2020 2:36 PM
To: Biblin, Janet, ACBH <[hidden email]>
Cc: SPSS List <[hidden email]>
Subject: Re: [SPSSX-L] Forcing a failure in batch mode.

 

I presume that by null, you mean sysmis in statistics.  Arithmetic with sysmis does not raise an error.  It just causes the result to be sysmis.

 

The INSERT command provides the ERROR keyword which can be set to CONTINUE (the default) or STOP.  (INSERT EXEC provides the ability to run alternative code in case of an error).

 

But you need to generate an error, not just a warning such as you would get from division by 0 or detect the condition some other way

 

So you could do something like this

 

 Compute ShowStopper = counter1+counter2+counter3.  

do if sysmis(ShowStopper).

    print outfile="t:/temp/error.txt' /$casenum.
end if.

where the outfile location is invalid (I have no t drive).

 

Ugly, but it would generate an error on that condition.  If you wrap this in an INSERT with ERROR=STOP, it should stop Statistics in its tracks.

 

 

 

On Wed, Mar 11, 2020 at 11:53 AM Biblin, Janet, ACBH <[hidden email]> wrote:

Hi

I need a way to force a failure in batch mode if certain conditions aren't met so the code will stop.

The code below doesn't work but hopefully explains the concept.

               If TotCount gt 3000 counter1 =1.

               If Agency1Count gt 2500 counter2 =1.

               If Agency2Count gt 500 counter3=1.

               Compute ShowStopper = counter1+counter2+counter3.

 

In case any of the values added are null I would like the code to throw an error since it can't add nulls.

I think this worked in earlier versions of SPSS, but either I am remembering wrong or SPSS has changed its handling of nulls.

Either way, I need all 3 conditions to be true or an error (not a warning) to be thrown. I am using SPSS 22.

 

Any help would be greatly appreciated.

 

Janet

===================== 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


 

--

Jon K Peck
[hidden email]

** This email was sent from an external source. If you do not know the sender, do not click on links or attachments. **

 



--
Jon K Peck
[hidden email]

===================== 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
Reply | Threaded
Open this post in threaded view
|

Re: Forcing a failure in batch mode.

Art Kendall
In reply to this post by janetB
Why do you want to force a stop?
Are you running on a system that charges for cpu time etc.?

Do you have millions of cases or extensive transformations so that a lot of
"wall time" would be saved?

Are you running simulations inside big loops?

YMMV. Forcing a stop on an error was important in the 70's when big jobs
could take 20 minutes of wall time.

Jon suggested PRINTing a message to an non-existent file.
Would it work to
(1) PRINT to an actual file including $csenum and other diagnostic info
(2)look at that actual file
(3) figure out correction/edits that (a)clean out all $sysmis values to be
user missing and (b)whatever else differs from your intention
(4) redraft the syntax.
(5) re-run the syntax?







-----
Art Kendall
Social Research Consultants
--
Sent from: http://spssx-discussion.1045642.n5.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
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: Forcing a failure in batch mode.

Rich Ulrich
In reply to this post by janetB
Art's reply reminds me that you don't really need to throw a FAILURE
as much as you need to STOP.

I don't remember that there is any ban on using an INSERT after
a DO IF.  You should be able to insert either the syntax that has all the
rest of your commands, or insert a short set of syntax that ends after
it prints out information (as Art suggests) that might be useful.

--
Rich Ulrich


From: SPSSX(r) Discussion <[hidden email]> on behalf of Biblin, Janet, ACBH <[hidden email]>
Sent: Wednesday, March 11, 2020 1:53 PM
To: [hidden email] <[hidden email]>
Subject: Forcing a failure in batch mode.
 

Hi

I need a way to force a failure in batch mode if certain conditions aren't met so the code will stop.

The code below doesn't work but hopefully explains the concept.

               If TotCount gt 3000 counter1 =1.

               If Agency1Count gt 2500 counter2 =1.

               If Agency2Count gt 500 counter3=1.

               Compute ShowStopper = counter1+counter2+counter3.

 

In case any of the values added are null I would like the code to throw an error since it can't add nulls.

I think this worked in earlier versions of SPSS, but either I am remembering wrong or SPSS has changed its handling of nulls.

Either way, I need all 3 conditions to be true or an error (not a warning) to be thrown. I am using SPSS 22.

 

Any help would be greatly appreciated.

 

Janet

===================== 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
Reply | Threaded
Open this post in threaded view
|

Re: Forcing a failure in batch mode.

Jon Peck
The trouble is that the code does not stop, because the sysmis value does not raise an error.  I have sent Janet a little Python file that conditionally executes an INSERT command based on the nonoccurence of a sysmis value in the computed variable.

On Thu, Mar 12, 2020 at 10:56 AM Rich Ulrich <[hidden email]> wrote:
Art's reply reminds me that you don't really need to throw a FAILURE
as much as you need to STOP.

I don't remember that there is any ban on using an INSERT after
a DO IF.  You should be able to insert either the syntax that has all the
rest of your commands, or insert a short set of syntax that ends after
it prints out information (as Art suggests) that might be useful.

--
Rich Ulrich


From: SPSSX(r) Discussion <[hidden email]> on behalf of Biblin, Janet, ACBH <[hidden email]>
Sent: Wednesday, March 11, 2020 1:53 PM
To: [hidden email] <[hidden email]>
Subject: Forcing a failure in batch mode.
 

Hi

I need a way to force a failure in batch mode if certain conditions aren't met so the code will stop.

The code below doesn't work but hopefully explains the concept.

               If TotCount gt 3000 counter1 =1.

               If Agency1Count gt 2500 counter2 =1.

               If Agency2Count gt 500 counter3=1.

               Compute ShowStopper = counter1+counter2+counter3.

 

In case any of the values added are null I would like the code to throw an error since it can't add nulls.

I think this worked in earlier versions of SPSS, but either I am remembering wrong or SPSS has changed its handling of nulls.

Either way, I need all 3 conditions to be true or an error (not a warning) to be thrown. I am using SPSS 22.

 

Any help would be greatly appreciated.

 

Janet

===================== 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


--
Jon K Peck
[hidden email]

===================== 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
Reply | Threaded
Open this post in threaded view
|

Re: Forcing a failure in batch mode.

Rich Ulrich
Jon,
Am I missing something? I don't see why Python works better than this.

 < some stuff >
DO IF   < data are okay >
INSERT  syntax that has the rest of the job
ELSE    < too few cases >
INSERT  syntax that ends, COMMENT or after writing a message, no commands necessary.

Or, is the problem that you need to create an error that aborts the batch stream? 
(Does an error abort a batch stream?  I think I haven't programmed a batch stream that
might throw a meaningful error since my DOS days.  Or my Vax-VMA days.)

Rich Ulrich


From: Jon Peck <[hidden email]>
Sent: Thursday, March 12, 2020 2:03 PM
To: Rich Ulrich <[hidden email]>
Cc: SPSS List <[hidden email]>
Subject: Re: [SPSSX-L] Forcing a failure in batch mode.
 
The trouble is that the code does not stop, because the sysmis value does not raise an error.  I have sent Janet a little Python file that conditionally executes an INSERT command based on the nonoccurence of a sysmis value in the computed variable.

On Thu, Mar 12, 2020 at 10:56 AM Rich Ulrich <[hidden email]> wrote:
Art's reply reminds me that you don't really need to throw a FAILURE
as much as you need to STOP.

I don't remember that there is any ban on using an INSERT after
a DO IF.  You should be able to insert either the syntax that has all the
rest of your commands, or insert a short set of syntax that ends after
it prints out information (as Art suggests) that might be useful.

--
Rich Ulrich


From: SPSSX(r) Discussion <[hidden email]> on behalf of Biblin, Janet, ACBH <[hidden email]>
Sent: Wednesday, March 11, 2020 1:53 PM
To: [hidden email] <[hidden email]>
Subject: Forcing a failure in batch mode.
 

Hi

I need a way to force a failure in batch mode if certain conditions aren't met so the code will stop.

The code below doesn't work but hopefully explains the concept.

               If TotCount gt 3000 counter1 =1.

               If Agency1Count gt 2500 counter2 =1.

               If Agency2Count gt 500 counter3=1.

               Compute ShowStopper = counter1+counter2+counter3.

 

In case any of the values added are null I would like the code to throw an error since it can't add nulls.

I think this worked in earlier versions of SPSS, but either I am remembering wrong or SPSS has changed its handling of nulls.

Either way, I need all 3 conditions to be true or an error (not a warning) to be thrown. I am using SPSS 22.

 

Any help would be greatly appreciated.

 

Janet

===================== 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


--
Jon K Peck
[hidden email]

===================== 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
Reply | Threaded
Open this post in threaded view
|

Re: Forcing a failure in batch mode.

Jon Peck
You can't put an INSERT command inside a transformation block.  Logically, a DO IF condition is evaluated for each case as the data are passed.  You wouldn't want to insert syntax into the job stream on every case, so the enclosing block is ignored for the insert, which also kills the loop or conditional block.

The user wanted to kill the syntax stream on a condition, but the expression involved produced only a sysmis result, not an error.  And warning do not stop procesing.

The Python code I wrote looks for a sysmis value in the result variable, ShowStopper here after the data pass is complete, and if one is not found, it runs an INSERT; otherwise it does nothng.

On Thu, Mar 12, 2020 at 10:39 PM Rich Ulrich <[hidden email]> wrote:
Jon,
Am I missing something? I don't see why Python works better than this.

 < some stuff >
DO IF   < data are okay >
INSERT  syntax that has the rest of the job
ELSE    < too few cases >
INSERT  syntax that ends, COMMENT or after writing a message, no commands necessary.

Or, is the problem that you need to create an error that aborts the batch stream? 
(Does an error abort a batch stream?  I think I haven't programmed a batch stream that
might throw a meaningful error since my DOS days.  Or my Vax-VMA days.)

Rich Ulrich


From: Jon Peck <[hidden email]>
Sent: Thursday, March 12, 2020 2:03 PM
To: Rich Ulrich <[hidden email]>
Cc: SPSS List <[hidden email]>
Subject: Re: [SPSSX-L] Forcing a failure in batch mode.
 
The trouble is that the code does not stop, because the sysmis value does not raise an error.  I have sent Janet a little Python file that conditionally executes an INSERT command based on the nonoccurence of a sysmis value in the computed variable.

On Thu, Mar 12, 2020 at 10:56 AM Rich Ulrich <[hidden email]> wrote:
Art's reply reminds me that you don't really need to throw a FAILURE
as much as you need to STOP.

I don't remember that there is any ban on using an INSERT after
a DO IF.  You should be able to insert either the syntax that has all the
rest of your commands, or insert a short set of syntax that ends after
it prints out information (as Art suggests) that might be useful.

--
Rich Ulrich


From: SPSSX(r) Discussion <[hidden email]> on behalf of Biblin, Janet, ACBH <[hidden email]>
Sent: Wednesday, March 11, 2020 1:53 PM
To: [hidden email] <[hidden email]>
Subject: Forcing a failure in batch mode.
 

Hi

I need a way to force a failure in batch mode if certain conditions aren't met so the code will stop.

The code below doesn't work but hopefully explains the concept.

               If TotCount gt 3000 counter1 =1.

               If Agency1Count gt 2500 counter2 =1.

               If Agency2Count gt 500 counter3=1.

               Compute ShowStopper = counter1+counter2+counter3.

 

In case any of the values added are null I would like the code to throw an error since it can't add nulls.

I think this worked in earlier versions of SPSS, but either I am remembering wrong or SPSS has changed its handling of nulls.

Either way, I need all 3 conditions to be true or an error (not a warning) to be thrown. I am using SPSS 22.

 

Any help would be greatly appreciated.

 

Janet

===================== 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


--
Jon K Peck
[hidden email]



--
Jon K Peck
[hidden email]

===================== 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