Showing posts with label SPSS error. Show all posts
Showing posts with label SPSS error. Show all posts

Saturday, June 28, 2014

There is extraneous text following the logical expression on a DO IF command. SPSS Error

I recently received the following error running an SPSS syntax with an "include" statement.

There is extraneous text following the logical expression on a DO IF command.

Now, I've been delinquent in setting up a number of syntax files to use as includes since I switched back to SPSS from SAS (not by my choice), so this threw me for a loop (no pun intended).

Oddly, if I ran the syntax that was calling the include then opened the include syntax and ran it separately, there was no problem.

What it turns out is that, if you're using a syntax file as an include, you cannot have leading space before your commands and arguments.  In my regular syntax files I add tabs to command arguments to show the separation, eg:

Do if thisvariable eq 'hello'.
     Compute thatvariable = 'hi'.
End if.

This runs fine in a syntax file, but if you use that syntax as an include, you get "There is extraneous text following the logical expression on a DO IF command."

Just switch to:

Do if thisvariable eq 'hello'.
Compute thatvariable = 'hi'.
End if.

I don't know how many other people in the world will ever experience this as it may just be my habit to add space like that, but I hope it helps someone!

*Edit - July 20th

Interestingly, if you have a subcommand that starts with a forward-slash you DO need a tab or set of blank spaces if it's part of an include.

For instance, this throws an error

Aggregate
/Outfile *
/Break id
/total = sum(avariable).
execute.

This will not.

Aggregate
   /Outfile *
   /Break id
   /total = sum(avariable).
execute.

Perhaps I'm just bad at SPSS and there was an unwritten rule that all subcommands and nothing else should start with a tab.  Oh well.  INCLUDE treats these all very unusually, in my opinion.