Saving SPSS Data and Output Files
Saving SPSS Data and Output Files
When attempting to save files from the SPSS software, it is important to first remember
that the only information that is saved is what it in the current window. For example, if
the currently displayed window contains the output from an anaylsis (frequency tables, t-
test results, graphs, etc.), the only information that will be contained in the resulting file
is the output. The information from the Data Editor will not be saved. In order to save the
information from the Data Editor, it must be active window by selecting Window at the
top of the screen and then selecting the Data Editor. Once the Data Editor has been made
the actice window, it can be saved.
The following illustrations provide a guide to saving Data and Output files in SPSS.
After the data has been entered into the Data Editor, it can be saved by selecting File and
Save or Save As.
Data Editor with Scores Entered Selecting File -> Save or Save As to save
the contents of the Data Editor
After selecting Save or Save As, the Save dialog box will appear. The name of the
datafile can be entered in the box labeled File name and the directory in which the file is
saved can be changed by selecting the down arrow on the right side of the box labeled
Save in.
File name: datafile1 Entered Changing Desired Directory
Note that the above procedure and dialog boxes will only appear the first time that a
file is saved or whenever Save As is chosen from the File menu. After a file has been
saved and new data is added, selecting Save from the File menu will automatically
replace the original file with the current data and use the existing file name. This is
the same procedure employed by most word processing and other software
programs.
The procedure for saving the output files is identical to the procedure for saving the data
files. After the output has been generated, the contents of the output window can be saved
by selecting File -> Save or Save As from the main menu in the Output window.
After selecting Save or Save As, the Save dialog box will appear. At this point the
procedure is the same as that outlined above for the data file. Since the SPSS Output file
has a different file ending (.spo instead of .sav for the data), the same name can be given
to the output file that was used for the SPSS Data file. When viewing the files through
My Computer, Windows Explorer, etc., the Data files will be identified as filename.sav
(and be labeled as an SPSS Data Document) and the Output files will be identified as
filename.spo (and be labeled as an SPSS Viewer Document).
Note that ,as mentioned above, the boxes will only appear the first time that a file is
saved or whenever Save As is chosen from the File menu. After an output file has
been saved and new analyses are conducted without closing the current output
window, selecting Save from the File menu will automatically replace the original
file with the current output and use the existing file name.
If the contents of the Data Editor were not saved prior to running the analysis, the Data
Editor window can be made the acitve window by selecting Window -> SPSS Data
Editor (see illustration below).
SPSS Files Data file (.sav) Output file (.spv) Printing in SPSS
If you want to include a copy of the data in the output file, use: Case
SummariesReportsAnalyze and then bring over all the variables you want to print
Under page attributes (from FILE tab): Include your name and date in the header Under
page setup (from FILE tab or Print Preview):
change to LANDSCAPE,
set all 4 margins to .3 inches
Highly suggest removing unwanted material
SAVE the output to your flash drive and give it a relevant name
Print choice 1: Print directly to printer
Print choice 2: (currently not available in PRST 1134 or 1135, but may be in Park Center)
You want to save the output in order to print at home or at other computer When printing,
print to a pdf file. You will be prompted to supply a name
Print choice 3: IF a pdf file is not an option, you can export the output to a word
document. From FILE tab, select Export Select shrink width to fit within page margins,
and check to see that page setup in export is set (landscape and .3)
Assign a relevant name for the Word document (.doc)
Transformation of data
In the six steps that follow, a transformation using SPSS Statistics is performed on the
following example data:
Data to Transform
36 32 45 41 29 22 18 36 10 40
3. Click on Transform > Compute Variable... in the top menu, as shown below:
4. You need to first select the function you would like to use. To do this, click "All" in
the Function group: box, then scroll down in the Functions and Special
Variables: box and click "Lg10" to select it.
Transfer the Lg10 function into the Numeric Expression: box by pressing the
button.
Click the Data variable in the left-hand box and then click on the button,
which will result in the expression you see in the Numeric Expression: box below.
All you need to do now is give this new variable a name. We have called the new
variable TrData . Type this name into the Target Variable: box in the top left-hand
corner.
5. Click on the button.
6. You will be presented with the SPSS Statistics Data Editor, which will now show
the log transformed data under the new variable name "TrData" that you defined,
as shown below:
.
What is Syntax?
FORMATTING
Statements in SPSS end with a period.
SPSS syntax is not case-sensitive. You can use all lower case,
all upper case, or a mixture of both when writing syntax.
COMMENTS
A comment is a line of text in a program that is not read by the
computer as a command. Comments do not affect how the
program functions; they exist purely for the humans reading and
writing the program. Comments help the reader understand what
the program is doing. In general, it is good practice to use brief
but descriptive comments in your code. Your comments should be
clear enough that a reader completely unfamiliar with your work
can understand what your program is doing.
In SPSS syntax, placing an asterisk (*) or a forward-slash followed
by an asterisk (/*) at the start of a line will turn all text on that
line into a comment. Hitting the Enter key will create a new, un-
commented line. Typically, comments in SPSS syntax are color-
coded with the color gray.
COLOR-CODING
By default, SPSS uses color and bolding to indicate the roles of the
words in the syntax.
SPSS Syntax Color Coding
The results for the command will appear in the Output Viewer
window.
Notice that there is also syntax printed above the descriptive
statistics in the output. The syntax provides a text-based map of
the command we just ran using drop-down menus. If we had
executed this syntax in a Syntax Editor window instead, we would
get the exact same results as we did using the drop-down menu.
When you are finished typing the syntax, you need to tell SPSS to
run the command by clicking the green arrow at the top of the
window. Voila! We have produced the very same output using both
drop-down menus and syntax.
Note: You can copy the syntax from an output window and paste
it into a new Syntax Editor window to re-use, modify, and save the
syntax. To copy syntax from the output (in the Output Viewer
window), simply click the syntax, copy it, and paste it into a
Syntax Editor window.
Modifying Syntax
Once you have syntax in the Syntax Editor window, you are free to
modify the syntax and/or save it. For example, perhaps I decide
that I want to look at some different variables, English and
Writing, and I would like to get the range statistic instead of the
minimum and maximum. I can easily modify the syntax I already
have to accommodate these changes:
After the previous example, it may seem like the menus are easier
to use than syntax. So why would anyone want to use syntax?
REPRODUCIBILITY
It is far easier to "retrace your steps" with syntax if you need to
recall the modifications you've made to your dataset. It's
also far easier to find and correct mistakes in your analysis if you
have the syntax, as opposed to if you had used the menus.
COMMUNICATION
It is much easier to communicate to others what actions you
performed in SPSS by showing someone your syntax than it is to
describe how you used the menus. The content of the menus and
dialog windows has changed over time with each version of SPSS,
while the syntax has remained relatively unchanged (though there
are a few notable exceptions).
Output Management System
The Output Management System (OMS) provides the ability to automatically write
selected categories of output to different output files in different formats
Can write output files into the following formats: • Word, Excel, PDF, SPSS (.sav) ,
Output file (.spv), web report format (.spw), XML, html and text
OMS provides a means to automatically writing pivot table output from a specific
procedure (e.g. Frequencies) to files in the above formats
Why use OMS ?
You might want to generate a table of summary statistics not available through the aggregate
procedure and merge them back with the original dataset
You might want to automatically exclude selected categories of output or specific items from the
Output viewer. i.e. you may want to exclude case processing summaries or some other output
The OMS control panel is used to both start and stop the routing of output to various destinations
or to exclude types of output from the Viewer Can create multiple independent OMS requests at
the same time
The same output can be routed to different locations in different formats
1) Specify the Output Type(s) 2) Select a Command Identifier(s) 3) Select table subtype(s)
4) Specify the format of the output file 5) Specify the destination of the output file 6)
Select if you want to exclude the output from the viewer 7) Add the OMS request
OMS Example
Look at creating some output using the training file “dietstudy.sav” “C:\Program Files\IBM\SPSS\
Statistics\*Version\Samples\English”
We will create a correlation matrix between using 10 tg & wtg variables and output this to an
SPSS file.
We can then calculate the average correlation
Open the Excel spreadsheet from which you wish to import data.
You can see in our example that we have 5 columns of data.
Before you begin the process of importing your data into SPSS, you need to ensure
that your variable names are in the first row of the worksheet, and that there is no gap
between the first and second rows. Our worksheet satisfies both these requirements.
It’s also wise to clean up your data. For example, if you had coded one of the Frisbee
Throwing Distance items as “50m” rather than just “50”, this would be a good time to
make a correction.
you can open up SPSS.
Once you’ve selected the options you require, and checked your data looks okay in the
preview window, press OK to begin the import.
To check this, click on the Variable View tab (see red arrow, above). This will bring up
the variable view within SPSS.
Variable View
As you can see from the image below, SPSS did a good job with our sample data,
correctly identifying SubjectID, Gender, DogOwner and FrisbeeThrowing as data type
numeric, and Education as data type string.
It also got level of measurement correct (see the Measure column), identifying
SubjectID, Gender, Education and DogOwner as nominal data, and FrisbeeThrowing as
scale (that is, as interval/ratio data).
Importing Data from a Text File
Data stored in text files have extensions such as *.txt, *.dat, or *.csv. These types of
data files are
simple to create and are not tied to a proprietary software, so they are a popular
choice for data files. While many computers will automatically open these file types
in a spreadsheet software like Microsoft Excel, they can be opened and edited using
any text editor program.
Importing text files into SPSS is slightly different than importing data in Excel
spreadsheets. There are several different patterns used to delineate the start and
end of a particular variable, and SPSS must know what pattern to follow in order to
read the data correctly.
Fixed-width data: Rather than using delimiters between observations, the values of
the variables are aligned vertically, so that a given variable always begins in a
certain column position. In the below example, ID always begins in column 1; Age
always begins in column 10; and Gender always begins in column 16.
ID Age Gender
A001R 41 F
Z009 36 M
C321BC 27 F
Files with the extension *.txt are called text files. This file type can contain fixed-
width or
delimited data. A common variation for *.txt files is tab-delimited data; that is, each
observation is separated by a tab (created using the Tab key on the keyboard).
However, *.txt files do not always use tabs as delimiters -- in fact, *.txt files can use
any character as a delimiter, including commas.
Files with the extension *.csv are called comma-delimited files; in this type of file,
the observations are delimited by a comma. Traditionally, the first row of a CSV file
contains the variable names (separated by a comma), and the first row of data
begins on the second line. Missing values are denoted using adjacent delimiters.
The process for importing any of these file types is virtually identical in SPSS, so
here, we will demonstrate using only a CSV file.
To import a CSV data file into SPSS, begin by clicking File > Open > Data. In the
Open Data window, change Files of type to "CSV (*.csv)". Locate your file and click
on it to select it, then click OK. This will start the Text Import Wizard process,
which will walk you through the process of specifying how SPSS should read and
interpret the data file.
Step 1 of 6
This window provides a preview of the data in your text file. The first step is to
indicate whether the data matches a predefined format, which would be a format
saved from a previous text file imported with the Text Import Wizard. (This would be
the case if you had already imported a text data file into SPSS in the past that was
formatted exactly the same way, and had chosen to save the import format during
the last step of the Text Import Wizard.) In most cases there will not be a predefined
format.
If your data matches a predefined format, click Yes and then browse for and upload
the file that defines the format.
If your data do not match a predefined format, click No, then click Next.
Step 2 of 6
If your data did not match a predefined format you will need to tell SPSS how your
data is arranged, so that it understands where one column ends and the next begins.
For text files, there are two types of "arrangements": delimited and fixed width. If
you are importing a CSV file, you have delimited data. You will also need to tell
SPSS if the datafile contains variable names. For CSV files, variable names are
typically included on the first line of the data file, before the data begins; however,
some datafiles do not include variable names.
In the "How are your variables arranged" area, click the radio button that matches
your data's format:
Delimited: Variable values are delimited (or separated) in the file by a special
character, such as a comma or a tab.
Fixed width: Variables are aligned in fixed width columns.
In the "Are variable names included at the top of your file" area, click Yes or No.
If necessary, choose the symbol used to denote decimals. Then click Next.
Step 3 of 6
We now need to tell SPSS what row our data begins on, and how many rows should
be read. For CSV files, the first row typically contains the variable names, and the
data values begin on line 2. However, you can choose to skip over certain lines if
necessary. (One example where this occurs is in Qualtrics survey data output to
CSV: The second row frequently contains variable labels, and oftentimes there may
be a third row containing import IDs, and the data actually begins on line 4.) Lastly,
if you only want to import a selection of cases -- for example, the first 1000 cases, or
a random sample of 10% of the cases -- you can opt to do so on this screen.
In the "Which delimiters appear between variables" area, select the check box that
reflects the delimiter used in your data. The delimiter is what is used to separate
values from each other within the data. The options include Tab, Space, Comma,
Semicolon, Other. If the text file is a .csv file, then the delimiter is a comma. If you
do not know which delimiter is used in the text file, refer to documentation that is
associated with your data or ask someone who knows how the data file was created.
The options Remove leading spaces from string values and Removing trailing spaces
from string values were added in SPSS version 25. If you are using SPSS version 24
or earlier, you will not see these options on this window.
SPSS attempts to guess what delimiters your file is using. For example, when using
the import wizard to import the sample data in *.csv format, SPSS guesses that both
commas and spaces were used as delimiters. Notice how that affects the parsing of
variable Major:
Because SPSS thinks that both spaces and commas were used as delimiters, it
thinks that the spaces occurring in the names of the majors delimit observations for
subsequent variables, and hence, SPSS interprets individual words as readings for
the adjacent variable(s) (here, variables Height, Weight, and Smoking). Clearing the
check box next to Space will correct this, and the change will be reflected in the
preview.
Notice, however, that there was still at least one case where the observation for
Major was incorrectly split across two columns. Notice how the value has double
quotes (") before the first word and after the last word. These quotes are being used
as the text qualifiers; that is, they indicate where the observation starts and ends.
To correct this, we need to change the text qualifier option to Double quote.
This step allows you to specify the format for each variable in the data file. In the
"Specifications for variable(s) selected in the data preview" area, SPSS explains
what criteria it uses to "guess" what format to use. In SPSS versions 24 and earlier,
the default format chosen for a given variable is based on the values present in the
first 200 records. In SPSS version 25, the default format chosen is based on 95% of
the cases.
In the Data Preview area, SPSS displays a preview of how your data will appear in
SPSS once the import is complete. You can select any of the variable names
(columns) in order to change the variable name or alter its format. For example, in
the example above we have selected the variable bday in the Data
Preview area. This variable name now appears in the Variable name area above, and
the Data format is also displayed—which, in this example, is Date/Time. You can
change the format of the variable by selecting a different format from the drop down
menu; here, we have selected mm/dd/yyyy to match the formatting of the
observations in this column. It is important to check every variable to make sure the
format and length is correct, rather than relying on SPSS to correctly identify the
variable formats; this ensures that you control exactly how each variable was read.
Step 6 of 6
In the final step, you can choose to save the file format that you just defined for the
current data file in case you will import data with the same structure and format in
the future. You can also choose to save the syntax, which is SPSS’s text-based
command language. Saving the syntax would allow you to format future data files in
the same way without having to manually select each of the options in the Import
Wizard again.
A preview of your data appears at the bottom of the dialog box. If you are satisfied
with the way the preview looks, click Finish to finalize the import. Now your data
should appear in SPSS in Data View window. It is a good idea to save your newly
imported data as an SPSS file (extension “.sav”) so that you can easily open the file
in SPSS in the future.
In any version of SPSS, you can open a text or CSV file by using File > Open >
Data. Prior to SPSS version 25, you could alternatively use File > Read Text
Data to begin importing a text or CSV file; this functioned identically to File > Open
Data. In SPSS version 25, Read Text Data has been removed from the File menu,
and replaced with the File > Import Data submenu.
Clicking File > Import Data > CSV will open the Read CSV File window:
This prompt attempts to simplify the import process, so certain actions (like
renaming variables before importing, or manually specifying variable formats) are
removed from this screen. If you need this level of control, you can click the
Advanced Options button; this will open the Text Import Wizard (described in the
previous section).
Another method
This dataset will be formatted as a CSV file. CSV stands for "comma separated values" and files with a ".csv" extension are text files
that are meant to be read as tables where every line represents a row and columns are separated by commas. SPSS can import data
from a CSV or any other text based file using the "File"->"Read Text Data..." option. This will open a pop-up dialogue which allows
the user to select the CSV file from the hard drive. Once the file has been selected, the "Text Import Wizard" will start. The import
process consists of six steps that can be cycled through using the "Back" and "Next" buttons at the bottom of the wizard.
Step 1:
SPSS allows the user to save the settings used to import files, and so this step is asking whether settings for this file have already been
saved of this computer. In this case they haven't, so mark "No."
Step 2:
In the second step, mark "Delimited" under "How are your variables arranged?" This tells SPSS that the data is formatted in units
divided by specific characters. Then check "Yes" under "Are variable names included at the top of your file?," which specifies that the
first line of the file contains the column headers for the table that holds the data. Columns in SPSS are frequently referred to as
variables.
Step 3:
This step controls which parts of the file will be pulled into SPSS. Since SPSS knows that the column names are on the first line, the
first case will automatically be set to "2." Each line represents a case, and we will want to import all lines.
Step 4:
Under "Which delimiters appear between variables?" check "Comma" and "Space." "Delimiters" are the characters that separate each
data value. Check "Double Quote" as the text qualifier, which is the character used to distinguish a single value. (This resolves any
ambiguity arising form values that contain commas).
Step 5:
Step 5 allows changes to be made to any of the variable data. You won't need to make any changes for this dataset, but in many
instances data sets will not have preimported variable names, or SPSS may not automatically recognize the correct "Data format." The
SPSS Data format format of a variable controls what type of value it contains: numbers are numeric and characters are strings. Other
types are also possible, like "Date," "Dollar," and "Scientific notation."
Step 6:
The final step allows the user to save the import configuration by checking "Yes" under "Would you like to save this file format for
future use?" The "Would you like to paste the Syntax?" option will print the command syntax to the output viewer. The "Cache Data
Locally" option makes a copy of the data in memory to improve performance. Depending on your computers memory you may need
to uncheck this for files larger than one or two gigabytes.
Then open your CSV in SPSS by going to File > Open and
selecting the .csv filetype from the dropdown menu, as
shown here:
After selecting your CSV file, you will be guided through
SPSS's Text Import Wizard. Follow the screen settings
below (most settings remain on their default option).
Screen 1: select Next