In SPSS you can program datasets in the SPSS syntax language. Unfortunately a lot of people working with SPSS do not really know how to use these syntax commands. A common way of using syntax is just do a “copy/paste” but barely knowing what the code really does. In order to solve this issue these series of SPSS syntax tutorials show, and explain how SPSS syntax can be used.
This tutorial is about how to define multiline comments, numeric and string variables in SPSS syntax code.
Howto define multiline comments in SPSS syntax
A common way to define comments, is using an asterisk in front of every comment line and end with a dot like:
1 2 3 4 5
* comment line 1. * comment line 2. * comment line 3. * comment line 4. * comment line 5.
It is much easier to use the multiline command:
1 2 3 4 5 6
COMMENT comment line 1 comment line 2 comment line 3 comment line 4 comment line 5.
The COMMENT command starts a comment block which can be closed with a dot at the end of the last comment block line. Keep in mind that your comment block does not contain line with a dot at the end, because otherwise your multiline comment block closes too early.
Howto define a numeric in SPSS syntax
The SPSS syntax code below shows the basics for defining a numeric variable. Each line of code is commented in order to show the purpose of the command.
1 2 3 4 5 6 7 8 9 10 11 12 13
* HOWTO DEFINE A NUMERIC VARIABLE. * The (F8.0) means a numeric with a length of 8 and 0 decimals. NUMERIC MYNUMERIC (F8.0). * Checks if MYNUMERIC is defined, if not it will become SYSMIS (optional). RECODE MYNUMERIC (ELSE=SYSMIS). * Sets the label for the variable to "my first numeric variable". VARIABLE LABEL MYNUMERIC 'My first numeric variable'. * Reads the active dataset and executes any pending commands. EXECUTE.
Howto define a string in SPSS syntax
The SPSS syntax code below shows the basics for defining a string.
1 2 3 4 5 6 7 8 9
* HOWTO DEFINE A STRING VARIABLE. COMMENT The A in (A8) means that the value is Alphanumeric (i.e. letters and numbers) The 8 means that the string has a maximum length of 8. STRING MYSTRING (A8). VARIABLE LABEL MYSTRING 'My first string variable'. EXECUTE.