Debugging SPSS Syntax
It has been said that Salesmanship starts after the prospect has said "no!". Similarly, programming could be said to start once there is a bug!
Index of common errors and possible solutions:
- This line of code does not work!
- My syntax works on a stand alone basis but fails when called via
DO IF … ELSE … END IFdoes not give the correct results!
- My vectors keep "disappearing"
SELECT IFdoes not select the correct cases!
- File is already in used
- Waiting for more inline data
Common errors and possible solutions
This line of code does not work!
Add a command terminator (a period) at the end of the preceding line. If the status bar indicates Transformations Pending click on Run Pending Transformations. Review the message in the log of the Output window.
I have also experienced situations where SPSS gets confused and does not recognize changes in a syntax file; it is as if SPSS continued to use the original syntax. Closing and restarting the software corrects those problems.
My syntax works on a stand alone basis but fails when called via
The syntax rules of the 2 run modes are slightly different. The main difference is that:
- Commands in an included file must begin in column 1,
- continuation lines must be indented at least one column
Thus the following works in immediate (direct, or interactive) mode:
DO IF (var1 > 0). COMPUTE var2=var1*2. END IF.
but it does not work in the Included mode because
COMPUTE does not start in column one. An alternative is to use a + or a - in the first column. The following would work
DO IF (var1 > 0). + COMPUTE var2=var1*2. END IF.
My DO IF … ELSE … END IF does not give the correct results!
My vectors keep "disappearing"
When you first create a vector say using
VECTOR a(20F8.0) /b=var1 TO var20. You can refer to each element using a LOOP for instance:
LOOP cnt=1 TO 20. - COMPUTE a(cnt) = cnt * 2. - COMPUTE b(cnt) = cnt +15. END LOOP.
As soon as you run a procedure or an
EXECUTE., the vectors are no longer available. If you need them again, you must redefine them but this time the command is different because variables a1 TO a20 and var1 TO var20 already exist.
You must use
VECTOR a=a1 TO a20 /b=var1 TO var20.
My SELECT IF does not select the correct cases!
If the calculation of the value tested is ok, then insert an
EXECUTE. in the line above the
SELECT IF. See also When to use
File is already in used
When I try, using syntax, to save a .sav file that already exists, I get a warning that the file already exists and that SPSS has renamed the file by placing a number on the end of the file name, e.g.
SAVE OUTFILE= 'Total.sav'.
results in total_1.sav being saved.
I really do want to save over the old files. Is there anyway to work around this "feature"?
Comments: This problem exits in versions 10.xx and has been heard in version 11. Before implementing the solution listed below, try to delete the files in question (in the example above: total.sav and totao_1.sav), if you can delete the files, things are fine. If you cannot, you need to re-start spss first.
*** Possible solution no 1. CACHE. EXECUTE.
SAVE OUTFILE= 'Total.sav'.
*** Possible solution no 2. SAVE OUTFILE='c:\temp.sav'. EXECUTE. SAVE OUTFILE= 'Total.sav'. EXECUTE. ERASE FILE='c:\temp.sav'.
Waiting for more inline data
One way this error occurs is when you have a
BEGIN DATA … END DATA block in your syntax and the END DATA does not start in the first column of the line.
To get rid of the message in the Processor Area of the status bar, place the cursor over the
END DATA command and run that line.