Debugging SPSS Syntax
Similarly, programming could be said to start once there is a bug!
- This line of code does not work!
- My syntax works on a stand alone basis but fails when called via
INCLUDE(link to the blog page)
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 use
- 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.
DO IF … ELSE … END IF does not give the correct results!
See Missing Values and DO IF.sps for a possible solution.
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.
SELECT IF does not select the correct cases!
Try to test the selection condition in a separate
COMPUTE. 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 use
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.