Sunteți pe pagina 1din 39

Institute for Digital Research and Education

INTRODUCTION TO SPSS SYNTAX 1


NOTE: This seminar was created using SPSS version 21. Some of the syntax
shown below may not work in earlier versions of SPSS.
Here are links for downloading the data les and the syntax le associated with
this seminar.

The data set called data13.sav (https://stats.idre.ucla.edu/wp-


content/uploads/2016/02/data13.sav) .
The data set called data13.xlsx (https://stats.idre.ucla.edu/wp-
content/uploads/2016/02/data13.xlsx) .
The data set called data13.dta
(/stat/spss/seminars/spss_syntax13/data13.dta) .
The data set called data13.sas7bdat (https://stats.idre.ucla.edu/wp-
content/uploads/2016/02/data13.sas7bdat) .
The data set called data13.csv (https://stats.idre.ucla.edu/wp-
content/uploads/2016/02/data13.csv) .
The SPSS program (/spss/seminars/spss_syntax13/part1_posted.sps) shown
in this seminar.

Here are links for the online movies presenting the material in this seminar (under
construction!!).

Online movie for the seminar, part 1


Online movie for the seminar, part 2
Online movie for the seminar, part 3
Online movie for the seminar, part 4

Introduction
The purpose of this seminar is to help you learn about the use of SPSS syntax as
an alternative to the point-and-click interface. In many instances, you may nd
that using syntax is simpler and more convenient than using point-and-click. The
use of syntax is very useful when doing data management. One reason is
because you can do repetitive tasks much quicker than you can using the point-
and-click interface. You can also see what you have typed, so you dont have to
point-and-click your way back to some window to be sure that you typed the
correct variable label, for example. The use of syntax is also helpful in
documenting your analysis. It is dicult to take adequate notes on modications
made to the data and the procedures used to do the analyses when using the
point-and-click interface. However, documenting what you are doing in a syntax
le is simple, and this makes reviewing and/or reconstructing the analysis much
easier.
All SPSS procedures and commands are executed using syntax, whether you use
the point-and-click interface or write your own syntax. Almost everything that you
can do in SPSS via point-and-click can be accomplished by writing syntax. (There
are a few exceptions, most notably when using the graph editors.) Also, there are
a handful of commands that are available via syntax that are not available via the
point-and-click interface, such as temporary and manova. There are several ways
in which you can get SPSS to show you the syntax that it is using to run your
analyses, and they are explained below.
Perhaps the simplest way to ease yourself into writing SPSS syntax is to notice the
syntax that SPSS includes above the results in your output le. In other words,
SPSS prints the syntax of each procedure immediately above the results. If you
are doing data management that does not produce results (such as creating a
new variable or sorting your data), then you simply see the syntax in the output
window. You can copy and paste that syntax from the output window into your
syntax le so that you have a complete record of your analysis. If you would
rather have the syntax go directly to the syntax le, you can click on the Paste
button instead of the OK button after you have set up your analysis. This will
paste the syntax that SPSS uses to run your analysis into a syntax window from
which you can run the commands.
Commands in the output le If for some reason the commands are not shown in
your output le, it is easy to have this done. To make this change, from the Data
Editor window, click on Edit, then on Options, and then on the View tab. In the
lower left-hand corner, check the option that says Display commands in log, and
you will see all of the commands issued from then on in your output window
immediately above the corresponding output.
The SPSS journal Finally, you can have the SPSS journal saved to a convenient
location. The journal is a log of all of the SPSS commands that have been issued
(output not included). To nd or change the location of this le, from the Data
Editor window, click on Edit, then Options, and under the File Locations tab, you
will see where SPSS is saving the journal le. You can change that location, and
you can indicate whether the journal should be overwritten every time you start
SPSS, or if your next session should be appended to the bottom of the existing
le. You can view the journal le using a text editor such as WordPad. Be aware
that the le might be quite long, so NotePad may not be able to open the le.
How to open a new or existing syntax le To open a new syntax le, from the Data
Editor window, click on File, then New, and then Syntax. If you want to open an
existing syntax le, you would click on File, then Open, and then on Syntax. A
syntax le is nothing more than a text le; hence, you can type commands and
comments into it, and you can cut-and-paste in it as you would in any text editor.
Unlike other types of SPSS les (such as data les), you can open syntax les in
any text editor, such as WordPad or NotePad.
How to run (execute) syntax Now that you have commands in your syntax le,
how do you run them? You have several options. You can highlight one or more
commands and click on Run at the top of the syntax window. You can then
selectAll, Selection, Current, or To End. You can highlight one or more commands
(including the period at the end) and click on the right-pointing arrow at the top of
the syntax editor. If you want to run only one command, you can simply put your
curser anywhere in the command and click on the right-pointing arrow. SPSS
while highlight and run that command. If you would rather not mouse to the top of
the syntax window, you can press Ctrl-R on your keyboard (after highlighting the
command or commands that you wish to run).
Multiple open data sets As of version 14, SPSS allows you to have multiple data
sets open at once. The syntax that you run will be run on the active data set.
The active data set is the one that is last one that you clicked on. If you get
strange error messages when you run your syntax, you may have run the syntax
on the wrong data le. If you did and you made changes to the data set that you
did not want to make, simply close the data set without saving it. This brings up a
good point: you should always work on a copy of your data, not on the original.
Keep the original somewhere safe where it cannot be overwritten. If you make a
mistake on the copy, it is no big deal; you just make another copy of the original
and continue working on that.
SPSS has a command that allows you to control which data set is active via syntax
(cleverly called dataset activate). We will explore the dateset commands later in
this seminar. To keep things simple, we are going to have only one data set open
at a time in this seminar.
A comment on comments One of the most important things to remember when
writing SPSS syntax is that all commands must end in a period (.). This includes
comments, which you can use pretty much anywhere in your syntax le. To start a
comment, use either an asterisk (*) or the command comment. If you forget to end
your comment with a period, SPSS will consider everything between comment or *
and the next period to be part of the comment, and you may be left wondering
why some of your commands did not run.
The SPSS syntax guide, AKA the SPSS Command Syntax Reference
You can access the SPSS syntax guide by clicking on Help and then Command
Syntax Reference from any of the SPSS windows (the Data Editor, Syntax or
Output windows). The Command Syntax Reference is a PDF that contains all of
the commands available in SPSS, listed in alphabetical order. If you do not have a
license for all of the SPSS add-on modules, you will not be able to run all of the
commands listed. There is usually a note at the top of the entry if the command is
part of a particular add-on module.
1. Opening data les
Perhaps the rst thing that you need to know when using SPSS syntax is how to
open a data le. The command for opening an SPSS data le is get le followed
by the path where the le is located and the name of the le to be opened. The
path and le name should be enclosed in quotes, and you need to include the le
extension, which is .sav for SPSS data les. The .zsav data le extension was
added in SPSS version 21 and denotes a compressed data le. If you have a .zsav
le, you need to use SPSS version 21 or later to open the le.
getfile"d:data13.sav".

If your data le is not in SPSS format, you may still be able to open it in SPSS. If
you have an Excel le, you can type
getdata
/type=xlsx
/file='d:datadata13.xlsx'.

Please note that there can be some issues when opening in Excel le in SPSS.
One common issue is that Excel will allow you to do things that SPSS (or any other
statistical package) will not. For example, you can put graphs and gures in the
middle of your Excel spreadsheet, but such spreadsheets cannot be opened in
SPSS. Excel allows you to use spaces in variable names, and this is not permitted
in SPSS.
If your data le is in Stata format, you can type
getstatafile='d:datadata13.dta'.

It is possible that the current version of SPSS may not be able to read in the
current version of a Stata data le.
If your data le is in SAS format, you can type
getsasdata='d:datadata13.sas7bdat'.

Please note that when using the get stata command, you need to use the le
keyword. When using the get sas command, you need to use the data keyword.
SPSS can also open other kinds of les, such as .csv les. These are text les that
have a comma or tab delimiter (in other words, the values of the variables are
separated by either a comma or a tab). When reading a comma separated values
(.csv) le into SPSS, you will need to specify the row number of the text le on
which the data begin as well as the name and format of the variables in the text
le.
getdata
/type=txt
/file='d:datadata13.csv'
/delimiters=","
/firstcase=2
/variables=
old_varf4.2
num1f8.2
num2f8.2
q1f8.2
q2f8.2
q3f8.2
q4f8.2
q5f8.2
q6f8.2
q7f8.2
q8f8.2
v1f8.2
puppyf8.2
v2f8.2
genderf4.2.
exe.

A note about quotes You can use either single or double quotes, as shown above,
as long as they match (obviously). Quotes must be used if you have spaces
anywhere in your path specication or data le name, for example, D:my
dissertationmy datathe current data set.sav. If you omit the quotes, you will get
an error message, and SPSS wont open your data le.
Password protection
Starting with SPSS version 21, you can password protect data les and output
les. You can do this either through the point-and-click interface or with syntax.
Syntax les cannot be password protected, so if you use syntax to set up the
password protection, you (or anyone else) can see what the password is. This is
not necessarily a bad thing; if you forget what the password is, the le cannot be
opened. On page 1865 of the SPSS 21 Syntax Reference Guide is this: Warning:
Passwords cannot be recovered if they are lost. If the password is lost the le
cannot be opened.
The password will also be displayed in the SPSS journal le. The password is
limited to 10 characters, and it is case sensitive. The password must be enclosed
in quotes and can include letters, numbers, symbols and punctuation.
***Please note that password protecting a data le is not a sucient method of
protecting the condential information of respondents. In other words, all of the
rules that apply to the handling of condential information are the same whether
you use password protection or not.
Active datasets
SPSS can have many datasets open at once. If you have more than one dataset
open, you need to be able to specify which dataset you want your syntax to
manipulate. This can be done with the dataset commands. The dataset
commands are a group of related commands that allow you to control the active
dataset. This group of commands includes dataset activate, dataset close,
dataset copy, dataset declare, dataset display and dataset name. Your syntax will
run on the active dataset. You can make any open dataset the active dataset
simply by clicking on it. When using syntax, the dataset activate command will
make the listed dataset the active dataset. You may need to use the dataset name
command before the dataset activate command, so that you can name the
dataset that you want to make active. The name you give the dataset will not
change the name of the dataset that is stored on your hard drive. We will see
examples of these commands later in this presentation.
The dataset copy command is very useful for making a backup copy of your
dataset. We always recommend that researchers work on a copy of their dataset
and keep the original in a safe place where it cannot be lost or overwritten. If a
mistake is made on the copy of the dataset, another copy can be made and the
syntax that you have written can be run to bring the new copy up to date.
The new le command clears the active dataset. You may want to use this
command when you are generating data within an input program.
We will start our presentation by creating some new variables. Two commands
that you can use to create numeric variables are compute and if. Be aware that
there is no then in SPSS syntax. SPSS will not create the new variables unless
we issue either the execute command or a procedural command. Examples of
procedural commands are list, regression and crosstabs. The procedure does not
have to use the newly created variable. In many of the examples below, the
execute command is technically unnecessary because we issue the procedural
command list immediately afterward. (We use the list command as a convenient
way of showing the output on this webpage; in practice, you would probably just
look at the Data Editor window.) However, including the execute does not cause
any problems, and it is handy to have in case you later change the syntax and
remove the command that cause the execution of the compute commands.
In the rst example, we show how to make a new variable that is a copy of a
variable that already exists in the data set. We create a new variable, creatively
named new_var, and set it equal to old_var. In the second example, we create a
variable called newvar123 and set it equal to a constant. In our example, we set
newvar123 equal to 0. At this point, every case has a value of 0 for this variable.
Next, we use some if commands to change the values of newvar123 according to
the values in the variables num1 and num2.
The point of the following examples is that you can make the rules for value
assignments as complicated as you need them to be. You can use multiple and or
or conditions in a single compute or if command. You can use either symbols or
letters to specify equality or inequality. Which you use is simply a matter of
personal preference. Note that spacing between variables and symbols is also a
matter of preference.
Less
Greater
than
Equal Not Less Greater than or
or And Or Not
to equal than than equal
equal
to
to
= ~= <> < <= > >= & | ~
eq ne lt le gt ge and or not

getfile"D:Datadata13.sav".
datasetnamedata13.
datasetactivatedata13.

*makingacopyofavariable:new_variable=old_variable.
computenew_var=old_var.

computenewvar123=0.
ifnum1=20newvar123=1.
ifnum1ge50ornum2<=70newvar123=2.
ifnum1=96andnum2=96ornum2=36newvar123=3.
execute.
listnum1num2old_varnew_varnewvar123.

num1num2old_varnew_varnewvar123

20.0020.001.001.002.00
20.0030.002.002.002.00
52.0036.004.004.003.00
63.0086.007.007.002.00
45.0072.009.009.00.
93.0012.002.002.002.00
28.0015.006.006.002.00
75.0046.005.005.002.00
96.0096.004.004.003.00
34.0036.001.001.003.00
73.0032.003.003.002.00
20.0030.003.003.002.00
55.0013.004.004.002.00
91.0029.009.009.002.00
78.0030.007.007.002.00

Numberofcasesread:15Numberofcaseslisted:15
You can use all sorts of math and functions when creating your variables. We will
show the use of many other functions a little later in this presentation.
computesum_num1_num2=num1+num2.
computemult_num1_num2=num1*num2.
computediv_num1=num1/6.56.
*clickonthevaluesofdiv_num1inthedataeditor.
execute.
listmult_num1_num2div_num1sum_num1_num2
/casesfrom1to10.

mult_num1_num2div_num1sum_num1_num2

400.003.0540.00
600.003.0550.00
1872.07.9388.00
5418.09.60149.00
3240.06.86117.00
1116.014.18105.00
420.004.2743.00
3450.011.43121.00
9216.014.63192.00
1224.05.1870.00

Numberofcasesread:10Numberofcaseslisted:10

Another point to be made involves the use of parentheses. How you use
parentheses can aect the resulting variable. Notice that the two if commands
below are the same, except for the use of the parentheses. The output of these
two commands are put into dierent variables so that you can compare the
results.
ifnum1=20andnum2=96ornum2=30newvar4=4.
ifnum1=20and(num2=96ornum2=30)newvar5=5.
exe.
listnum1num2newvar4newvar5.

num1num2newvar4newvar5

20.0020.00..
20.0030.004.005.00
52.0036.00..
63.0086.00..
45.0072.00..
93.0012.00..
28.0015.00..
75.0046.00..
96.0096.00..
34.0036.00..
73.0032.00..
20.0030.004.005.00
55.0013.00..
91.0029.00..
78.0030.004.00.

Numberofcasesread:15Numberofcaseslisted:15

The commands below are very similar to the commands above. The point of this
example is to illustrate how SPSS processes the commands. In this example, the
output of the two if commands are put into the same variable, newvar6, so that
you can see what is happening.
ifnum1=20andnum2=96ornum2=30newvar6=4.
ifnum1=20and(num2=96ornum2=30)newvar6=5.
exe.
listnum1num2newvar4newvar5newvar6.

num1num2newvar4newvar5newvar6

20.0020.00...
20.0030.004.005.005.00
52.0036.00...
63.0086.00...
45.0072.00...
93.0012.00...
28.0015.00...
75.0046.00...
96.0096.00...
34.0036.00...
73.0032.00...
20.0030.004.005.005.00
55.0013.00...
91.0029.00...
78.0030.004.00.4.00

Numberofcasesread:15Numberofcaseslisted:15

SPSS has many functions that can be used to create new variables. We will look
at a few below. As you can see, you can use multiple functions to create a new
variable.
computenvexp=exp(num1).
computenvlg10=lg10(num2).
computenvln=ln(num2).
computenvr1=rnd(num1,1).
computenvt3=trunc(num1,3).
computenvrandom=rv.normal(100,10).
computenvlag=lag(num1).
computenvrndmean=rnd(mean(sqrt(num1),sqrt(num2)),.01).
exe.
listnvexpnvlg10nvlnnvr1nvt3nvrandomnum1nvlagnvrndmean.

nvexpnvlg10nvlnnvr1nvt3nvrandomnum1nvlagnvrndmean

5E+0081.303.0020.0018.0090.9020.00.4.47
5E+0081.483.4020.0018.0099.6320.0020.004.97
4E+0221.563.5852.0051.0097.2452.0020.006.61
2E+0271.934.4563.0063.0096.4063.0052.008.61
3E+0191.864.2845.0045.0081.4445.0063.007.60
2E+0401.082.4893.0093.0082.3393.0045.006.55
1E+0121.182.7128.0027.0096.8328.0093.004.58
4E+0321.663.8375.0075.00116.3475.0028.007.72
5E+0411.984.5696.0096.0098.1396.0075.009.80
6E+0141.563.5834.0033.0096.8334.0096.005.92
5E+0311.513.4773.0072.0096.6073.0034.007.10
5E+0081.483.4020.0018.0088.4020.0073.004.97
8E+0231.112.5655.0054.00114.2755.0020.005.51
3E+0391.463.3791.0090.0091.2891.0055.007.46
7E+0331.483.4078.0078.0095.5378.0091.007.15

Numberofcasesread:15Numberofcaseslisted:15

A note on naming variables


In the preceding examples, the naming of the variables has not been terribly
good. We do not suggest that you name your variables newvar1, newvar2, etc.
Rather, it is good practice to name your variables something meaningful (and easy
for you to type). Variable names can be up to 64 bytes long (approximately 64
characters long). However, please remember that you cannot use spaces in a
variable name, and variable names should not have an underscore at the end, as
these might conict with variables created by commands or procedures. Variable
names should also not end with a period, as the period is the command
terminator in SPSS. (In other words, the period tells SPSS where each command
ends.) You can use any combination of upper and lower case letters in a variable
name, but SPSS is case insensitive. In other words, the variable name might be
VarName, but you can type varname, VARname or VARNAME in the syntax, and it
will work ne.
The shift values command
The shift values command was introduced in SPSS version 17. It is used to create
new variables that have the shifted values of another variable in the active
dataset. As you can see in the third example, you can make multiple new
variables in a single call to the shift values command. Note that the keyword
variable cannot be shorten to var.
shiftvaluesvariable=num1result=nvsv1lag=1.
shiftvaluesvariable=num1result=nvsv2lead=2.
shiftvaluesvariable=num1result=nvsv3shift=3
/variable=num1result=nvsv4shift=2
/variable=num1result=nvsv5shift=1.
listnum1nvsv1tonvsv5.

num1nvsv1nvsv2nvsv3nvsv4nvsv5

20.00.52.00...
20.0020.0063.00..20.00
52.0020.0045.00.20.0020.00
63.0052.0093.0020.0020.0052.00
45.0063.0028.0020.0052.0063.00
93.0045.0075.0052.0063.0045.00
28.0093.0096.0063.0045.0093.00
75.0028.0034.0045.0093.0028.00
96.0075.0073.0093.0028.0075.00
34.0096.0020.0028.0075.0096.00
73.0034.0055.0075.0096.0034.00
20.0073.0091.0096.0034.0073.00
55.0020.0078.0034.0073.0020.00
91.0055.00.73.0020.0055.00
78.0091.00.20.0055.0091.00

Numberofcasesread:15Numberofcaseslisted:15

The create command


The create command uses functions to make new variables. A few of these
functions, such as the lag function, are available with other commands. However,
create has many functions that are unique to the command. Please see our SPSS
FAQ: What kinds of new variables can I make with the create command?
(/spss/faq/what-kinds-of-new-variables-can-i-make-with-the-create-command/) or
the Syntax Reference Guide for a list of these functions.
In the rst example, we use the lag function to create the new variable nvcr1,
which is num1 lagged by 1. In the next example, we create the new variables
nvcr2 to nvcr5 as the lag of num1. The variable nvcr2 is lagged 2 steps, the
variable nvcr3 is lagged 3 steps, and so on.
createnvcr1=lag(num1,1).
createnvcr2tonvcr5=lag(num1,2,5).
listnum1nvcr1tonvcr5.

num1nvcr1nvcr2nvcr3nvcr4nvcr5

20.00.....
20.0020.00....
52.0020.0020.00...
63.0052.0020.0020.00..
45.0063.0052.0020.0020.00.
93.0045.0063.0052.0020.0020.00
28.0093.0045.0063.0052.0020.00
75.0028.0093.0045.0063.0052.00
96.0075.0028.0093.0045.0063.00
34.0096.0075.0028.0093.0045.00
73.0034.0096.0075.0028.0093.00
20.0073.0034.0096.0075.0028.00
55.0020.0073.0034.0096.0075.00
91.0055.0020.0073.0034.0096.00
78.0091.0055.0020.0073.0034.00

Numberofcasesread:15Numberofcaseslisted:15

In the examples below, we use the csum and the di functions. The csum function
creates a cumulative sum, and the di function gives the dierence between
values of the original variable. The degree of the dierence must be specied.
createnvcr6=csum(num2).
createnvcr7=diff(num2,1).
listnum2nvcr6nvcr7.
num2nvcr6nvcr7

20.0020.00.
30.0050.0010.00
36.0086.006.00
86.00172.0050.00
72.00244.0014.00
12.00256.0060.00
15.00271.003.00
46.00317.0031.00
96.00413.0050.00
36.00449.0060.00
32.00481.004.00
30.00511.002.00
13.00524.0017.00
29.00553.0016.00
30.00583.001.00

Numberofcasesread:15Numberofcaseslisted:15

Creating binary variables


Binary variables are variables that have only two values, 0 and 1 (and possibly
missing). Here are two examples of methods that you can use to create binary
variables.
computenvbinary=(gender=2).
freqvar=nvbinary.

The equivalent code is presented below.


*computenvbinary=0.
*ifgender=2nvbinary=1.
*ifmissing(gender)nvbinary=$sysmis.
*exe.

We can use the any function to recode certain values of a variable into 1 in the
new variable nvany.
computenvany=any(num1,20,52,63).
freqvar=nvany.
The equivalent code is presented below.
*computenvany=0.
*ifnum1=20ornum1=52ornum1=63nvany=1.
*ifmissing(num1)nvbinary=$sysmis.
*exe.

System variables and logical operators


System variables are variables created during your current SPSS session that
contain system-required information. You can access these variables when you
need to, but they dont appear in your dataset unless you explicitly access them.
All system variable names start with a dollar sign ($). There are eight system
variables, but we will only mention two of them here. As we saw in the example
above, you can assign system-missing values (.) with the system variable $sysmis.
System missing values are considered the lowest possible value in SPSS, which
you may need to know when sorting a variable that contains system missing
values. In the rst example below, we will use the system variable $casenum to
indicate the case number.
A note about specifying missing values: When you are specifying missing values
in variables that already exist in the dataset, use a function (such as missing,
sysmis, etc.). When assigning a value of system missing to a variable that you are
creating, use $sysmis. Also, these points are made on page 125 of the SPSS
Command Syntax Reference Guide:

When two relations are joined with the AND operator, the logical
expression can never be true if one of the relations is indeterminate. The
expression can, however, be false.
When two relations are joined with the OR operator, the logical expression
can never be false if one relation returns missing. The expression, however,
can be true.

computemy_id=$casenum.
computenvmiss=0.
ifq1=3nvmiss=$sysmis.
listmy_idq1nvmiss.
my_idq1nvmiss

1.003.00.
2.002.00.00
3.003.00.
4.004.00.00
5.008.00.00
6.008.00.00
7.003.00.
8.004.00.00
9.001.00.00
10.002.00.00
11.003.00.
12.003.00.
13.009.00.00
14.00..00
15.002.00.00

Numberofcasesread:15Numberofcaseslisted:15

computenvmiss1=1.
listnvmiss1.

my_idq1nvmiss

1.003.00.
2.002.00.00
3.003.00.
4.004.00.00
5.008.00.00
6.008.00.00
7.003.00.
8.004.00.00
9.001.00.00
10.002.00.00
11.003.00.
12.003.00.
13.009.00.00
14.00..00
15.002.00.00

Numberofcasesread:15Numberofcaseslisted:15

ifq1=3andnotsysmis(q3)nvmiss1=2.
listq1q2q3nvmiss1.

q1q2q3nvmiss1

3.003.00.1.00
2.002.009.001.00
3.001.002.002.00
4.001.002.001.00
8.001.003.001.00
8.002.001.001.00
3.009.004.002.00
4.004.002.001.00
1.001.001.001.00
2.009.003.001.00
3.003.002.002.00
3.001.001.002.00
9.004.004.001.00
.2.004.001.00
2.003.001.001.00

Numberofcasesread:15Numberofcaseslisted:15
if~(sysmis(q1)andsysmis(q2)andsysmis(q3))nvmiss1=$sysmis.
listq1q2q3nvmiss1.

q1q2q3nvmiss1

3.003.00..
2.002.009.00.
3.001.002.00.
4.001.002.00.
8.001.003.00.
8.002.001.00.
3.009.004.00.
4.004.002.00.
1.001.001.00.
2.009.003.00.
3.003.002.00.
3.001.001.00.
9.004.004.00.
.2.004.00.
2.003.001.00.

Numberofcasesread:15Numberofcaseslisted:15

computenvmiss2=1.
if~(sysmis(q1)|sysmis(q2)|sysmis(q3))nvmiss2=$sysmis.
listq1q2q3nvmiss1nvmiss2.

q1q2q3nvmiss1nvmiss2

3.003.00..1.00
2.002.009.00..
3.001.002.00..
4.001.002.00..
8.001.003.00..
8.002.001.00..
3.009.004.00..
4.004.002.00..
1.001.001.00..
2.009.003.00..
3.003.002.00..
3.001.001.00..
9.004.004.00..
.2.004.00.1.00
2.003.001.00..

Numberofcasesread:15Numberofcaseslisted:15

The numeric command


The numeric command allows you to specify the format of the new variable. The
numeric command creates an empty variable that you then populate using
another command, such as the compute or if command. In the rst example
below, we create a numeric variable called nvn1. Because we did not list a format
on the numeric command, this variable has the default format, which is f8.2. This
means that the variable has a length of 8, with 2 spaces after the decimal, 1 space
for the decimal, and 5 spaces for integer portion of the number. In the second call
to the numeric command, we create two new variables, nvn2 and nvn3. These
two variables have dierent formats. The three compute commands populate our
three new variables.
numericnvn1.
numericnvn2(f4.0)nvn3(f8.4).
computenvn1=q1.
computenvn2=q1.
computenvn3=q1.
exe.
listq1nvn1nvn2nvn3.

q1nvn1nvn2nvn3

3.003.0033.0000
2.002.0022.0000
3.003.0033.0000
4.004.0044.0000
8.008.0088.0000
8.008.0088.0000
3.003.0033.0000
4.004.0044.0000
1.001.0011.0000
2.002.0022.0000
3.003.0033.0000
3.003.0033.0000
9.009.0099.0000
....
2.002.0022.0000

Numberofcasesread:15Numberofcaseslisted:15

This brings up the topic of changing numeric formats, which can be done with the
formats command.
formatsnum1(dollar6)num2(f4.1).
exe.
listnum1num2.

num1num2

$2020.0
$2030.0
$5236.0
$6386.0
$4572.0
$9312.0
$2815.0
$7546.0
$9696.0
$3436.0
$7332.0
$2030.0
$5513.0
$9129.0
$7830.0

Numberofcasesread:15Numberofcaseslisted:15
The formats command only works with numeric variables. This command does
not change how many decimal places you see in tables in your output (the only
output modied by this command is the output for the list command), and it does
not change the actual values used by SPSS when doing computations. However, it
can be very useful when making graphs with the ggraph command and GPL.
Please see Making Graphs with the ggraph command and GPL (/spss/library/spss-
librarymaking-graphs-with-the-ggraph-command-and-gpl/) for more information
and examples.
Creating standardized variables
Creating standardized variables in SPSS is very simple. You can use the
descriptives command with the save subcommand. If you want to name the new
standardized variable instead of using the SPSS default name, you can put that
name in parentheses after the variable you wish to standardize. You can also
create multiple standardized variables in a single call to descriptives.
descriptivesnum1
/save.
descnum1(num1z)
/save.
descq1(q1z)q2(q2z)q5(q5z)
/save.

Note that a variable label was automatically created for the new variables. We
also see that the command descriptives is another command name that can be
shortened (to desc).

The keyword to
SPSS uses special keywords to identify commands, subcommands, functions
operators and other specications. Some of the keywords that we will use in this
presentation include to, all and thru.
When creating variables, the SPSS keyword to will create variables with
consecutive numbering. When using to in syntax to refer to variables that already
exist in the data set, SPSS assumes that variables are sequential, or positionally
consecutive (all variables between the rst variable listed and the last variable
listed in the command will be included). There are some commands in SPSS that
will use the keyword to in both a positionally and a numerically consecutive
manner, depending on whether existing variables are being modied in some way
or whether new variables are being created. Some of these commands include
autorecode, recode, aggregate and rename variables.
autorecodev1tov2/intonvar1tonvar3.
renamevariables(q6toq8=q16toq18).
computenvmean5=mean(q1toq5).
exe.
listv1tov2nvar1tonvar3q16toq18nvmean5.
v1puppyv2nvar1nvar2nvar3q16q17q18nvmean5

7.005.002.007429.0010.007.002.67
8.009.003.008836.0011.005.001.00
5.006.006.005563.0016.003.002.25
3.003.009.003398.0015.009.00.50
2.001.008.002185.0011.005.00.50
6.002.008.006282.0014.001.003.50
9.005.007.009477.0017.008.00.00
4.007.005.004655.0018.005.003.25
1.008.004.001742.0012.002.001.00
8.007.002.008621.0014.009.00.50
5.003.001.005314.0019.006.003.25
7.009.003.007837.0015.003.002.00
4.006.006.004568.0016.007.00.25
1.005.008.001485.0015.004.002.33
2.001.007.002172.0017.001.002.50

Numberofcasesread:15Numberofcaseslisted:15

Renaming variables
The rename variables command does exactly what you think it does: it renames
variables. If you rename more than one variable at a time, you may need to use
parentheses. You can also use this command to exchange variable names, as
shown in the third example.
renamevariablesnvbinary=female.
*parenthesesareoptional.
renamevariables(q16=q6)(q17=q7)(q18=q8).
*parenthesesnotoptional.
renamevariables(q6q7q8=q16q17q18).
*exchangingvariablenames.
renamevariables(q16=q18)(q18=q16).

Recoding variables
The recode command recodes the values of either numeric or string variables.
There are several input keywords that you can use with this command, including
lo, lowest, hi, highest, thru, missing, sysmis and else. The keyword thru includes
the specied end value. The keywords lowest and highest (and lo and hi) include
user-dened missing but not system-missing values. The keyword missing
species both user-dened missing and system missing, while the keyword
sysmis only species system-missing. Output keywords include copy and sysmis.
There are other keywords that can be used when recoding string variables, but
we will not cover those here.
recodeq1(1=4)(2=3)(3=sysmis)(else=copy)intoq1r.
crosstabs
/tables=q1byq1r.
listq1q1r.

q1q1r

3.00.
2.003.00
3.00.
4.004.00
8.008.00
8.008.00
3.00.
4.004.00
1.004.00
2.003.00
3.00.
3.00.
9.009.00
..
2.003.00

Numberofcasesread:15Numberofcaseslisted:15

recodenum1(lowestthru30=1)(31thru40=2)(41thruhi=3)(missing=9)intonum1r.
crosstabsnum1bynum1r.

formatsnum1(f8.2).
listnum1num1r.
num1num1r

20.001.00
20.001.00
52.003.00
63.003.00
45.003.00
93.003.00
28.001.00
75.003.00
96.003.00
34.002.00
73.003.00
20.001.00
55.003.00
91.003.00
78.003.00

Numberofcasesread:15Numberofcaseslisted:15

Delete variables
The delete variables command is a very handy command, but obviously, this
command needs to be used with caution. The delete variables command was
introduced in SPSS version 12.
deletevariablesnum1rq1r.

Another way to do the same thing is to use the save outle command with either
the keep or the drop subcommand. The dierence is that with the delete
variables command, you are not saving a new data le.
saveoutfile"D:DataSeminarsSPSSSyntaxSeminar2013updatedata13_deleted.sav"
/dropnum1rq1r.

Variable level
The variable levels are shown in the Variable View window of the Data Editor in
the second column from the right. With earlier versions of SPSS, the only
procedure that used the variable level was igraph, which is now a deprecated
graphing command. However, in more recent versions of SPSS, other procedures
are making use of the variable levels, so it is becoming more important that users
know how to modify them. Here is a simple example.

variablelevelnum1num2(scale)
/q1toq5(ordinal)
/gender(nominal).
Variable role
The variable role command was introduced in SPSS version 18, and it is used with
some of the commands that were introduced in that and later versions of SPSS.
Some of the roles a variable can take include input (independent variable), target
(dependent variable), both and none. The specied role does not matter when
you are writing syntax, but it does matter when you are using the point-and-click
interface. This command is mentioned in our seminar on SPSS syntax because
we realize that many people will use the point-and-click interface to help them get
a template of the syntax for a procedure, and it can be confusing when some
variables appear in some dialog boxes and not others.
variablerole
/targetnum1
/inputq1toq5
/bothnum2.

Sorting variables
The sort variables command was introduced in SPSS version 16. You can sort the
variables in your dataset by name, type, format, label, values, missing, measure,
role, columns, alignment, and attribute. Sorting variables is a good way to make
sure that you have done all of the data documenting that you meant to do (by
sorting the variables by labels or values, for example). We will cover the topic of
documenting data shortly.
sortvariablesbytype.
sortvariablesbyrole.
sortvariablesbyname.

User-dened missing values


There are two dierent types of missing data in SPSS: system-missing and user-
dened missing. System-missing is displayed as a dot (.) in the column of a
numeric variable. System missing values are considered the lowest possible
value in SPSS. You can dene your own missing values, which are called user-
dened missing for numeric variables. Although displayed dierently, both
system-missing and user-dened missing values are just missing values to SPSS,
and they are treated the same way (except in lter variables, see below). Both will
be deleted from analyses that call for listwise deletion. The only dierence is
that they will be displayed in separate categories in crosstabs, frequencies, etc.
There are some keywords that can be used with numeric value lists, and they
include lo, lowest, hi, highest and thru.
missingvaluesq1toq5(9).
missingvaluesq3(7thruhi,999).

You can declare, change or clear missing values by issuing the missing values
command again. To clear all missing values, simply leave the parentheses empty.
missingvaluesq1(98).
missingvaluesq5().

It is important to realize is that you can create the same variable in dierent ways,
and that the missing values may be handled dierently. Note that above we
dened -8 and -9 as missing values for the variable q1 (in the third missing values
command), and -9 as a missing value for the variable q2 (in the rst missing values
command).
computenvmiss1=q1+q2.
computenvmiss2=sum(q1,q2).
exe.
listq1q2nvmiss1nvmiss2.

q1q2nvmiss1nvmiss2

3.003.006.006.00
2.002.004.004.00
3.001.004.004.00
4.001.005.005.00
8.001.00.1.00
8.002.00.2.00
3.009.00.3.00
4.004.008.008.00
1.001.002.002.00
2.009.00.2.00
3.003.006.006.00
3.001.004.004.00
9.004.00.4.00
.2.00.2.00
2.003.005.005.00

Numberofcasesread:15Numberofcaseslisted:15
Documenting data
There are many ways to document your data using SPSS. We have already
covered some of these topics, and we will discuss some others shortly.

create document
label data le
label variables
label values of variables
user-dened missing
create variable attributes
create datale attributes
set variable role
set variable level

You can view the documentation that you have created using the sysle info and
display commands. When using the sysle info command, you must specify the
le path. Also, the maximum length of a variable label is 255 characters and the
maximum length of a value label is 120 bytes (approximately 120 characters). The
display command allows you to display certain information about the dataset and
the variables within it. For example, you can display all of the variable names,
documents, dictionary information, attributes, labels, scratch variables, vector
names and macros.
Lets look at some of the commands that we can use to archive information about
our data le.
The document command is very handy and allows you to keep notes with your
data set. You can use the document drop command to remove a document from
your data le. The add document command can be used to include additional
notes to your document. Unlike the document command, you will need to use
quotes around each line of the text when using this command.
The le label command is used to label the data le itself. This is particularly
useful when you have multiple copies of a data set that are slightly dierent.
The variable labels command allows you to assign labels to your variables. Doing
so is an important part of developing a codebook. We strongly recommend that all
data sets have a codebook, even if the researcher is not planning on sharing the
data with others. The codebook reminds you of all of the details of your data set,
which is important when you have to come back to the data at a later time.
The value labels command allows you to assign labels to the values of a variable.
You can use the add value labels command to labels values that were not labeled
with the value labels command.
sysfileinfo"D:DataSeminarsSPSSSyntaxSeminar2013updatedata13_doc.sav".
documentThesedatawerecollectedfromJanuary13,2012throughJune20,2012.
adddocument"thisismyadditionalcomment"
"tomyoriginaldocumentcommand.Note"
"thateachadditionallineoftextmustbeenclosedinquotes.".
displaydocument.

*dropdocuments.
filelabelSPSSSyntaxSeminarPart1datafile.
saveoutfile"D:DataSeminarsSPSSSyntaxSeminar2013updatedata13_doc2.sav".
sysfileinfo"D:DataSeminarsSPSSSyntaxSeminar2013updatedata13_doc2.sav".

variablelabelsq1"answertoquestion1"
q2"answertoquestion2".
displaylabels.

valuelabelsq1toq3q51'stronglydisagree'2'disagree'3'agree'.
addvaluelabelsq54'stronglyagree'5'notapplicable'.
freqvar=q1toq5.
saveoutfile"D:Datadata13_doc3.sav".
displaydictionary
/variables=q1toq5q1zq2z.
displaysorteddictionary
variables=q1toq5q1zq2z.

The variable attribute command


The variable attribute command was introduced in SPSS version 14 and allows
users to assign attributes to variables in the active dataset. The attributes are
saved with the data dictionary. In the examples below, we assign attributes that
tell us what type of response was required for q1 and what formula was used to
create the variable nvrndmean. This type of information is important to keep with
the dataset, especially if the written code book becomes lost.
variableattribute
variables=q1
attribute=answerformat('circleone')
/variables=nvrndmean
attribute=formula('rnd(mean(sqrt(num1),sqrt(num2)),.01)').
displayattributes.
The datale attribute command
The datale attribute command is similar to the variable attribute command, but,
of course, it sets attributes for the data le. The delete keyword allows attributes
to be removed.
datafileattribute
attribute=Version('1')
CreationDate('2/11/2013')
Update1('2/12/2013').
displayattributes.

datafileattribute
delete=Update1.
displayattributes.
The codebook command
The codebook command was introduced in SPSS version 17 and updated in
version 18. The codebook command displays dictionary information and summary
statistics for variables in the active dataset. For nominal and ordinal variables,
summary statistics include counts and percents. For scale (continuous) variables,
the mean, standard deviation and quartiles are displayed. The split le status of
the dataset is ignored, but the lter status is honored for computing summary
statistics.
In the interest of saving space, only part of the output from the rst codebook
command is shown.
codebooknum1num2q1toq3
/varinfolabelvaluelabelsmissingattributes
/statisticscountmeanstddev
/fileinfonamelocationlabeldocumentscasecount.
codebooknum1num2
/optionsmaxcats=5sort=descending.
Subsetting data using the split le, lter and select if commands
Up to now, we have been focusing mostly on data management. However, the
reason researchers do data management is to prepare the data for analysis, and
we will see some descriptive statistics shortly. First, though, lets talk about
subsetting data. There are several dierent ways that you can do this in SPSS.
Perhaps the simplest way is to have SPSS run the same analysis for each level of
a categorical variable. In our sample dataset, lets say that we want to get the
mean of some variables for each level of the variable gender. We will use the split
le command to do this. Before we can issue this command, we will need to sort
the data by gender.
If we had any missing values on the variable gender, our output would be broken
into three sections: one for missing values of gender, one for gender = 1 and one
for gender = 2.
sortcasesbyfemale.
splitfilebyfemale.
descnum1num2.
splitfileoff.
descnum1num2.

Sometimes you want the analysis only for one gender, not both. Of course, you
could use the split le command and only look at the output for the gender of
interest, but if your analysis takes a long time to run, this can be a problem. There
are at least two ways to analyze only one subset of your data. You can use a lter
or you can keep only the cases that you want to analyze in your dataset. Usually,
researchers prefer to create and use a lter rather than eliminate cases from the
dataset. To lter cases in SPSS, you need a binary variable (a variable that only
has the values 0 and 1) and use that variable with the lter command. Only the
cases coded as 1 will be included in the analyses; the cases coded as 0 (or
missing) will not. The lter command will stay in eect until you turn it o with
the lter o command (or the use all command). You can look in the lower right
corner of the SPSS data window to see if a lter is on.
filterbyfemale.
descnum1num2.

filteroff.
*useall.
descnum1num2.

You can permanently delete cases from your dataset with the select if command.
Cases coded as 1 will remain in your dataset; cases coded as 0 (or missing) will be
deleted from the dataset. Once you run the select if command, you will not be
able to recover the cases that were deleted. If you delete cases that you did not
intend to delete, close the data le without saving it and reopen the data le.
We do not want to permanently delete any cases from our sample data le, so we
will put the temporary command before the select if command. The temporary
command is available only via syntax (not through the point-and-click menu
system). The temporary command stays in eect only until the next executable
command is executed. That is why the output for the rst list command (which is
the rst executable command after temporary) has only seven observations (the
seven that met the criteria listed on the select if command), while the second list
command includes all of the observations from our data set. Although for this
seminar we only use the temporary command while subsetting, it has many other
uses.

temporary.
selectif(gender="f"andq1ge2).
listnum1.


num1

20.00
20.00
52.00
93.00
75.00
73.00
55.00
78.00

Numberofcasesread:8Numberofcaseslisted:8


listnum1.

num1

20.00
20.00
52.00
93.00
75.00
73.00
55.00
78.00
63.00
45.00
28.00
96.00
34.00
20.00
91.00

Numberofcasesread:15Numberofcaseslisted:15

The n of cases command


Another way to use only part of your data is to use the n of cases command. This
command will limit the number of cases in the active dataset to N cases (of
course, you decide what N will be). This command is especially handy when you
have a very large dataset, you are debugging your syntax and running a
command takes longer than you would like. You can simply limit the number of
cases such that your commands run quickly, so that you can see if you get any
error messages, if you have all of the desired options specied, etc. We will use
the temporary command with the n of cases command in the examples below.
Also note how the n of cases works with the sample and select if commands: If N
OF CASES is used with SAMPLE or SELECT IF, the program reads as many
records as required to build the specied n cases. It makes no dierence whether
N OF CASES precedes or follows SAMPLE or SELECT IF (page 1363).
temporary.
nofcases3.
listmy_idnum1.

my_idnum1

1.0020.00
2.0020.00
3.0052.00

Numberofcasesread:3Numberofcaseslisted:3

temporary.
nofcases3.
selectiffemale=1.
listmy_idfemalenum1.

my_idfemalenum1

4.001.0063.00
5.001.0045.00
7.001.0028.00

Numberofcasesread:3Numberofcaseslisted:3

listmy_idfemalenum1.

my_idfemalenum1

1.00.0020.00
2.00.0020.00
3.00.0052.00
4.001.0063.00
5.001.0045.00
6.00.0093.00
7.001.0028.00
8.00.0075.00
9.001.0096.00
10.001.0034.00
11.00.0073.00
12.001.0020.00
13.00.0055.00
14.001.0091.00
15.00.0078.00

Numberofcasesread:15Numberofcaseslisted:15
The sample command
You can also use the sample command to limit the number of cases in the active
dataset. This command can be used in two ways. You can specify the proportion
of cases you want to keep in the active dataset (by giving a decimal value
between 0 and 1), or you can specify the number of cases (n) to be sampled from
a specic number of cases (m). You may want to set the seed before running the
sample command, as it uses a pseudo-random number generator to select the
cases. If you want to get the same cases each time you run the command, you
will need to set the seed.
setseed1326.
temporary.
sample.5.
listmy_idnum1.

my_idnum1

2.0020.00
6.0093.00
7.0028.00
14.0091.00

Numberofcasesread:4Numberofcaseslisted:4

If you specify m less than the actual number of cases in the active dataset, the
sample will be drawn only from the rst m cases. If you specify m greater than the
number of cases in the active dataset, the sample will be an equivalent proportion
of cases from the active dataset. Hence, in our second example, we sample 4
cases from 20, but we only have 15 cases in our active dataset. Four cases out of
20 is 4/20 = .2, and .2 proportion of 15 cases is 3.
setseed1472.
temporary.
sample4from10.
listmy_idnum1.

my_idnum1

1.0020.00
3.0052.00
7.0028.00
8.0075.00

Numberofcasesread:4Numberofcaseslisted:4

setseed159122.
temporary.
sample4from20.
listmy_idnum1.

my_idnum1

6.0093.00
8.0075.00
10.0034.00

Numberofcasesread:3Numberofcaseslisted:3

The output commands


Just as there is a group of dataset commands, so there is a group of output
commands. These commands allow you to control output les via syntax. The
group of output commands includes output activate, output close, output display,
output export, output name, output new, output open and output save.
The Output Management System (OMS)
In addition to controlling output les, you can control parts of the output from a
procedure. This is done with the Output Management System, or OMS. OMS is
particularly useful when you need to get one or more specic values from an
output and use those in the next step of your analysis or program. For example,
you may want to capture the regression coecients from one model and use
them with a dierent data set. The group of OMS commands includes oms,
omsend, omsinfo and omslog. We have some examples using the OMS
commands at SPSS FAQ: How can I output my results to a data le in SPSS?
(/spss/faq/how-can-i-output-my-results-to-a-data-le-in-spss/) and SPSS FAQ: How
can I use aggregate and OMS to help explain a three-way interaction in ANOVA?
(/spss/faq/how-can-i-use-aggregate-and-oms-to-help-explain-a-three-way-
interaction-in-anova/) .
Saving SPSS les
You can save your SPSS data les with the save outle command. All you need
after the command is the le path and the name of the new data set.
saveoutfile"D:datanew_data13.sav".

There are several handy subcommands that you can use when saving your data
le. For example, you can use the keep subcommand. As you would expect, you
list the variables that you want to save in the new data set on the keep
subcommand. You can order them in any order that you want them in the new
data set. In this example, we move the variables gender, num1 and num2 so that
they are the rst variables in the new data set (called my_data13.sav), and then we
keep all of the other variables in the order in which they appear in the old data set
(data13.sav) by using the SPSS keyword all. If you want to delete a few variables
from the new data set, you can use the drop subcommand and list the variables
that should not be included in the new data set (no example shown). If you want
to delete cases from the saved dataset, you can lter your data le and use the
unselected subcommand to delete the ltered cases.
saveoutfile"D:datamy_data13_keep.sav"
/keep=gendernum1num2all.

filterbyfemale.
saveoutfile"D:datamy_data13_female.sav"
/unselected=delete.
You can also save your data le in dierent formats. In the example below, we
save our data le in Stata format. Please note that as of SPSS version 21, SPSS
can save data in Stata versions 4 through 8 (Stata version 8 is the default). This is
usually not a problem, because the current version of Stata can read Stata 8 data
les. Also, keep in mind that SPSS data les can have many more variables than a
Stata Intercooled data le can have (the limit in Stata IC is 2048). This means that
you may need to delete some variables from your SPSS data le before running
the save translate command.
savetranslateoutfile="D:Datamy_data13.dta"
/version=8
/type=stata
/edition=intercooled.

Here is an example of saving an SPSS data le as a SAS version 9 data le.


savetranslateoutfile="D:datamy_data13.sas7bdat"
/valfile="D:datalabels.sas"
/version=9
/platform=windows
/replace.

In the rst example below, we save our SPSS data le as a comma separated
values (.csv) le without the variable names at the top of the le. This is good for
making an Mplus data le. In the second example, we include the variable names
at the top of the le and use the value labels instead of the data values.
*savingacommaseparatedvaluesfilewithoutvariablenamesatthetop.
*goodformakingMplusdatafiles.
savetranslateoutfile="D:datamy_data13_nonames.csv"
/type=csv.

*csvfilewithnamesatthetopandlabels.
savetranslateoutfile="D:datamy_data13_names.csv"
/type=csv
/fieldnames
/cells=labels.

If you want want to save your output le, you can use the output export
command. Please see our FAQ on this.
SPSS output les have the le extension .spv. You can also save output les with
the .spw extension, which is for the SPSS Web Reports format. Older SPSS output
les may have the extension .spo. These les can be read with the SPSS Smart
Viewer, which can be downloaded for free from the IBM SPSS website. Note that
only .spo les that were created using a Windows machine can be read with the
SPSS Smart Viewer.
You can save SPSS syntax les. They have an .sps extension. SPSS syntax les
are simply text les, so they can be opened and read in any text editor. Despite
much wishful thinking, there is no command to translate your SPSS syntax les
into SAS or Stata syntax les. Sorry.
The erase command
You can remove les from your computer by using the erase command. You can
remove only one le at a time with this command, and wildcard characters are not
permitted. You can remove les created by SPSS as well as les not created by
SPSS. As noted on page 701 of the Syntax Reference Guide: Use ERASE with
caution. Obviously, this is very good advice. Below is an example.
erasefile="D:datamy_data13_names.csv".

Pasting syntax
When using the point-and-click interface in SPSS, you have the choice of clicking
on OK or Paste once you have set up your analysis or data management
command. If you click on Paste, SPSS will put the syntax for that command in your
syntax le without running it. This can be a useful way to learn SPSS syntax, but
be aware that you may see much more syntax than you actually need to run a
command. Also note that SPSS uses capitalization to show which words are part
of the SPSS syntax and which are supplied by the user (such as variable names).
As we mentioned before, SPSS is not case sensitive, so there is no need to type
SPSS command names, subcommand names or keywords in capital letters if you
rather not. Lets look at one example.
Notice that we get exactly the same output using both of the examine commands
shown below. As you can see, when you paste the syntax, SPSS includes many of
the default options, and these clutter the syntax. It is a good idea to play around
with syntax that you have pasted to see what subcommands can be eliminated
without changing the output. In the example above, all of the subcommands can
be eliminated.
GET
FILE='D:data13.sav'.

*pointandclicksteps.
analyzedescriptivesexplore.

EXAMINE
VARIABLES=num1BYgender
/PLOTBOXPLOTSTEMLEAF
/COMPAREGROUP
/STATISTICSDESCRIPTIVES
/CINTERVAL95
/MISSINGLISTWISE
/NOTOTAL.

examinenum1bygender.

Plugins
SPSS Programmability Extension allows you to expand the capabilities of SPSS by
adding new procedures written in such languages as Python, R Java and the .NET
version of Microsoft Visual Basic. You can download these plugins from the IBM
SPSS website. Please note that you need to install the version of the plugin that
matches the version of SPSS that you are running. Please see http://www-
142.ibm.com/software/products/us/en/spss-stats-programmability/ (http://www-
142.ibm.com/software/products/us/en/spss-stats-programmability/) for more
information.
For more information
We have many Learning Modules (/spss/modules/) and Frequently Asked
Questions (/spss/faq/) that will provide additional information:

SPSS Learning Modules (https://stats.idre.ucla.edu/spss/modules/)


Inputting raw data into SPSS (/spss/modules/how-to-read-raw-data-into-
spss/)
Creating and recoding variables (/spss/modules/creating-and-recoding-
variables/)
Using SPSS functions for making/recoding variables (/spss/modules/using-
spss-functions-for-making-and-recoding-variables/)
Subsetting variables and observations (/spss/modules/ubsetting-data/)
How can I analyze a subset of my data? (/spss/modules/how-can-i-analyze-
a-subset-of-my-data/)
Labeling and documenting data (/spss/modules/labeling-and-documenting-
data/)
SORT and SPLIT BY (/spss/modules/using-the-sort-cases-and-split-le-
commands/)
Missing data in SPSS (/spss/modules/missing-data/)
How can SPSS help me document my data? (/spss/faq/how-can-spss-help-
me-document-my-data/)
How can I see the number of missing values and patterns of missing values
in my data le? (/spss/faq/how-can-i-see-the-number-of-missing-values-and-
patterns-of-missing-values-inmy-data-le/)
How can I easily convert a string variable into a categorical numeric
variable? (/spss/faq/how-can-i-easily-convert-a-string-variable-to-a-
categorical-numeric-variable/)
How do I standardize variables in SPSS? (/spss/faq/how-do-i-standardize-
variables-in-spss/)
How can I move my data from SPSS to Mplus? (/spss/faq/how-can-i-move-
my-data-from-spss-to-mplus/)
What kinds of variables can I make with the create command?
(/spss/faq/what-kinds-of-new-variables-can-i-make-with-the-create-
command/)
What are some of the dierences between the compute, create and shift
values commands? (/spss/faq/what-are-some-of-the-dierences-between-
the-compute-create-and-shift-values-commands/)
How can I analyze my data by categories? (/spss/faq/how-can-i-analyze-my-
data-by-categories/)
What does the keyword to indicate in SPSS? (/spss/faq/what-does-the-
keyword-to-indicate-in-spss/)
How can I output my results to a data le in SPSS? (/spss/faq/how-can-i-
output-my-results-to-a-data-le-in-spss/)
Why cant I see my variables in some of the SPSS dialog boxes?
(/spss/faq/why-cant-i-see-my-variables-in-some-of-the-spss-dialog-boxes/)

We also have some books that you can check out from our Stat Books for Loan
(/books/) , including

SPSS Programming and Data Management: A Guide for SPSS and SAS
Users, Fifth Edition by Raynald Levesque
An Intermediate Guide to SPSS Programming: Using Syntax for Data
Management by Sarah Boslaugh
SPSS 19 Guide to Data Analysis by Marija J. Norusis
(http://www.norusis.com/index.php)
SPSS For Windows: Step by Step (http://www.abacon.com/george/data.html)
by Darren George and Paul Mallery
SPSS for Psychologists, Third Edition
(http://www.palgrave.com/products/Catalogue.aspx?is=1403987874) by
Nicola Brace, Richard Kemp and Rosemary Snelgar
Next Steps with SPSS (http://www.sagepub.com/booksProdDesc.nav?
prodId=Book9892) by Eric L. Einspruch
The SPSS Book by Matthew J. Zagumny

Click here to report an error on this page or leave a comment


How to cite this page (https://stats.idre.ucla.edu/other/mult-pkg/faq/general/faq-how-
do-i-cite-web-pages-and-programs-from-the-ucla-statistical-consulting-group/)

2017 UC REGENTS TERMS OF USE & PRIVACY POLICY (http://www.ucla.edu/terms-of-use/) HOME (/) CONTACT (/contact)

S-ar putea să vă placă și