It is easy to forget that when you are
using the SPSS drop-down menus to
explore and analyze data, than what you
are really doing is writing code.
SPSS requires computer code - called syntax -
that actually makes the analysis run.
When you know about syntax, you have a
secret weapon for making SPSS more
powerful. We are going to dive deeper
into how to use syntax in SPSS.
The best way to explain syntax is to
show it to you in action so imagine that
I'm doing a class project using the data
set demo SAV open SPSS and then open the
demo data set I will begin by running a
few analyses I will get the descriptive
statistics and frequencies for marital
status including a bar chart with
percentages then I'm going to run a
t-test to see whether males or females
have higher average income
finally I will correlate household
income with years of current address and
the years with current employer so
notice what I have done with each of
these examples for each test instead of
clicking ok I clicked the paste button
with each analysis syntax has been added
to my syntax window now before I close
this data set double click in the output
and select this set of commands that
opened the data set I will add them to
the top of my syntax window save the
syntax to the desktop
and then close SPSS
so we will pretend that it has been a
few days since I have created the syntax
and used this data set I begin by
opening SPSS once the software opens I'm
going to open the syntax window even if
I can't remember where I left my dataset
all I need to do is press the green
triangle to run selection SPSS finds and
opens the data set it runs each of the
analyses and everything is available in
the output window I can now use the
export command to export everything to
Microsoft Word so why am i showing you
this
in addition to being pretty cool that I
can run an entire analysis with just a
few clicks there's some tremendous
benefits to using syntax
syntax allows you to automate common
tasks saving the syntax from an analysis
especially a complex analysis in which
you are making small tweaks to variables
or settings allows you to repeat an
analysis without having to go through
each step using the drop-down menus if
we are collaborating on a project and
the analysis is complex I do not have to
try to explain each step to you using
the drop-down menus and settings I can
simply email you the syntax and the data
set you open the data run the syntax and
you have replicated my analysis perhaps
as part of our project you have new data
to add to the data set well the thing is
I have already run an analysis no
problem
you can add your new data to our data
set you make your additions and then you
rerun the tests as long as the variable
names in your data set are the same as
in mine
you can use my syntax or you can edit my
syntax to work with your variable names
another big advantage to knowing how to
use syntax is there are some things that
you simply cannot do with drop-down
menus you must use the command syntax
language and as you have seen you do not
need to learn how to code to use syntax
in SPSS SPSS will write this syntax for
you and you can copy or edit as you
please the only downside is that the use
of syntax may or may not be available
with the limited student versions of
SPSS if not you will need to go to your
computer lab to use the full version at
your University
you can edit SPSS syntax or write your
own
look at this syntax syntax has both
commands in the dark blue and sub
commands in green the first line
frequencies is the command bar chart is
a sub command we know that it is a sub
command by the slash in front of it
notice that the frequencies command does
not have a slash I asked for the bar
chart to show percentages but perhaps I
would rather report for the raw numbers
or the frequencies all I need to do is
delete the word percent I know that I
want to report frequencies but perhaps I
can't remember what the precise command
is if I type an F SPSS will show me my
options for the bar chart I can choose
the frequency option return add two
spaces and then type a forward slash to
create a new sub command let's change
the format it is okay if you do not know
all of the commands just begin typing
and you can see the options I will sort
descending which is devalue using the
right click I can click anywhere inside
of a command then select the command and
then I can right click again and choose
run selection
another helpful feature is to follow the
color code of the syntax when the
command is recognized it turns red as
long as the command is red it is not
ready to run yet if you misspell a
command it will not turn red as you
would expect the syntax must be followed
by a period in order to run you can add
comments to your syntax using the
command comment however I think it is
easier to simply use an asterisk this is
a good place to add your research
questions right before an analysis so
you will know which research question
the analysis refers to notice how the
command following the comment will be
grayed out until you add a period at the
end of the comment and finally the
syntax is not case-sensitive the
convention however is to type commands
and sub commands in all caps and the
name of the variables in lowercase
you do not need to run the entire block
of syntax at once
in fact sometimes you only want to run a
small portion then stop look at the
output and then run the next portion to
do this use breakpoints breakpoints
allow you to stop the execution of a
syntax command at a certain point and
then continue running the syntax when
you are ready breakpoints must be set at
the level of the command not within the
command so you cannot stop at a sub
command to insert a breakpoint click
anywhere within the command in the left
column click on the red circle icon to
insert the breakpoint it will be
inserted after the command when you run
the syntax the run will stop at the red
circle to resume running choose run
continue
I mentioned a scenario in which you and
I are collaborating and I send you a
data set with syntax what do you do then
well first open the data set double
click on the SPSS data set to open it
now double click on the syntax file
commands will only run on the active
data set you can have other datasets
open just make sure that you have the
one that you want to use pulled to the
front if not you will get an error
message about not being able to find the
variable names you are now ready to run
this syntax on your data set
I have other things that I will teach
you about using syntax but for now just
know that when you use SPSS you are
actually writing computer code and
knowing how to use that computer code
can save you lots of time and make you a
power user with SPSS
you