Index of SPSS Tips
|Say your initial data file is named "mydata.sav". It is a good practice to never modify that file by syntax. Instead, the first time you save the data file by syntax, save it under a new name such as "mydata mod.sav". This is necessary to avoid accidentally crippling you original data file with commands such as SELECT IF or AGGREGATE.|
|When you work on a complicated syntax, periodically save the current version under a different name.|
It is very useful to customize the toolbars (refer to the User Guide for instructions). This is my Syntax Window toolbar.
|Number||Description of use|
|1||Empty the data editor|
|2||Open a new syntax window|
|3||Open a new script window|
|7||List the most recently used procedures|
|13||Run the command on which the cursor is positioned|
|14||Run the selected lines of syntax|
|15||Run syntax from the command on which the cursor is positioned to the end of the syntax|
|16||Run the complete syntax in the syntax window|
|18||When the cursor is on a command (for example FLIP or DO REPEAT), a window containing a brief description of the syntax for the command pops up.|
|20||This opens the spssbase.pdf file (the electronic version of the Syntax Reference Guide). I use this all the time.|
|21||This has the same effect as entering an EXECUTE command. It gets ride of the "Transformation Pending" message in the status bar. Very convenient.|
|22||This is an "home made" icon. It is linked to the Empty Designated Output window.sbs scripts. When I write / debug syntax, I click this icon before each run, this way I have only fresh output in the Output window.|
|There are many circumstances where one need change the paths contained in
a syntax file. For instance
I handle these situations by defining a macro at the beginning of the syntax file:
define !Path1 ()'d:\project xy\my program files\'!enddefine. define !Path2 ()'d:\project xy\my data files\'!enddefine. GET FILE=!Path2+"data1.sav". INCLUDE !Path1+"evaluate.sps". *** note that evaluate.sps should refer to !path1 and !Path2 *** *** do other calculations here ***. SAVE OUTFILE=!Path2+"results.sav".
With the above method, changing paths is done only once per syntax file.
|Ideally, you should include a sample initial data file as
well as the desired result file. More advanced users should (when the data file is
relatively complex) do this using DATA LIST or INPUT PROGRAM as this saves a lot of
time to the person trying to answer the question. In some cases it took me as long
to create the dummy data file as it took to solve the problem. The easier you make
it for the potential solver, the greater your chances that he / she will devote time to
help you out.
In summary, you may simplify the example to make it easier to understand but to get a solution which really solves you problem, you should mention the elements listed above in order to described the full context.
Asking the right question remains the best strategy to get the right answer...
Students or teachers (who have access to huge libraries...) often ask questions of the type "Does anybody have a syntax to calculate statistics XYZ as described in Book ABC?". This is certainly a short way of asking a complex question but those of us who do not have readily access to a university library simply skip the question...If you have scanned pages of the formulas and could email them to persons interested, say so. Do not attach these documents to you postings.
Understanding the following Q and A might save yourself a lot of problems. This was posted to the SPSSX-L list on 1999/02/04 by
If a Syntax file is called through an INCLUDE command, it is recommended to have a comment ( a line which starts with an * and ends with a period) in the first line of the syntax. This is to circumvent reported occurrences of the interpreter silently "swallowing" the first line code.
Note that the syntax of file which are to be run using the INCLUDE command needs to follow special rules:
For instance, the following code works in direct mode but does not work when invoked using the INCLUDE command:
DO IF $CASENUM=1.
Either of the following variation does work when the code is invoked by INCLUDE:
DO IF $CASENUM=1.
DO IF $CASENUM=1.
See Execute selective portions of syntax.SPS for a typical use of the INCLUDE command. It is important to know that the processing of a file that is called by the INCLUDE command stops as soon as an error occurs. Some warnings also stop the execution of the file.
The following 2 situations are common with INCLUDE files.
|Assuming the variable names are the same, all you have to do
is use the menu FILE > APPLY DATA DICTIONARY ...
OR using syntax:
To apply the Variable Label and Value Labels of a given variable to other variables, see this syntax.
|The easiest way to have multi-line comments in a syntax file
- to indent the second and subsequent lines
- avoid periods at the end of all but the last line.
That way a single * (or "Comment" key word) is needed at the beginning of the comments.