Remove Value Label from Multiple Variables

Question “I’d like to completely remove the value label from a value for many variables at once. Is there an easy way to accomplish that?” SPSS Python Syntax Example begin program. variables = ‘v1 to v5‘ # Specify variables here. value = 3 # Specify value to unlabel here. import spss,spssaux vDict = spssaux.VariableDict(caseless = True) varList […]

SPSS – Splitting a String Variable

After importing some data into SPSS, some answers ended up in a single string variable. The data are in splitstrings.sav, part of which is shown below. Excel has a nice “text to columns” function to split it but SPSS hasn’t…So you think you can syntax?Then let’s go and split this string into the original answers. Step 1 – New […]

SPSS VECTOR – Quick Tutorial

In SPSS, a VECTOR is a list of (new or existing) variables that can be referenced by their indices in this list.VECTOR is often combined with LOOP. Creating Dummy Variables with VECTOR and LOOP SPSS Vector – Basic Example Suppose we’d like to Creating Dummy Variables in SPSS for a variable holding values 1 through 4. We’ll call […]

Suffix All Variable Names

Question “I have a data file in which all variables were measured in 2012. I’d like to suffix their names with “_2012”. What’s the easiest way to do this?” SPSS Python Syntax Example begin program. variables = ‘v5 to v10‘ #Specify variables to be suffixed. suffix =’_2012‘ # Specify suffix. import spss,spssaux oldnames = spssaux.VariableDict().expand(variables) […]

Apply Dictionary Information from Excel

Question “I have an Excel workbook whose three sheets contain data values, variable labels and value labels. How can I apply the dictionary information from these last two sheets to the SPSS dataset after importing the data values?” Option A: Python A nice and clean option is to have Python read the dictionary information from the Excel sheets. The […]

SPSS Datasets Tutorial 1 – Basics

Introduction SPSS dataset logic is not always logical. However, for working proficiently with datasets, just a handful of basics is sufficient. These are explained in this tutorial. This tutorial focuses on working with SPSS datasets. For a definition and some background on datasets, see SPSS Datasets. Working with SPSS Datasets It is recommended you follow along with the […]

SPSS INSERT Command

Definition SPSS Insert is a command for running syntax files from within another syntax file. This may help keeping your syntax organized. SPSS Insert Command – Why Use It? Executing all of your commands from syntax may be the single best practice for working with SPSS. One of the reasons is that you can correct steps early […]

Python Xlrd (Excel Read) Module

xlrd is a module that allows Python to read data from Excel files. This tutorial explains where to get it and how to install it. Downloading the Python Xlrd Module The Python xlrd (short for “Excel Read”) module can be found here. After downloading it, you can extract the contents (twice) with 7 Zip. Copy the path of the folder that […]

SPSS – Change Value Labels with Python

A local supermarket held a small survey, the data of which are in minisurvey.sav. Unfortunately, the software for downloading the data in SPSS format prefixes all variable and value labels with the variable names. The screenshot below shows part of the data. Undesired Prefixes in Value Labels Clicking on some value labels in variable view confirms that they’ve […]

SPSS – Create Several Excel Files with Python

A teacher held a course evaluation. The data in SPSS format are in course_evaluation.sav, part of which is shown below. Students from different majors participated and now the education director wants separate Excel files for each major. A super easy way for creating these is by using SPSS with Python. We’ll walk you through. 1. Save SPSS Data as […]

SPSS – Batch Process Files with Python

Running syntax over several SPSS data files in one go is fairly easy. If we use SPSS with Python we don’t even have to type in the file names. The Python os (for operating system) module will do it for us. Try it for yourself by downloading spssfiles.zip. Unzip these files into d:\spssfiles as shown below and you’re good to go. Find All Files […]

SPSS Python Examples

Learn Python for SPSS the right way by running some of the examples below. They show precisely how to get things done in SPSS the fastest way possible and are easily modified to suit your needs. Enjoy! Latest SPSS Python Examples Batch Process Files with Python Create Several Excel Files with Python Change Value Labels with Python SPSS with […]

SPSS FORMATS – Set Display Format for Variables

SPSS FORMATS sets formats -decimal places, dates, percent signs and more- for numeric variables. Setting variable formats in SPSS does not change your actual data values. However, formats determine how your data are displayed -in the data viewer as well as the output-window. Two main uses of FORMATS are increasing or decreasing the decimal places of standard numeric variables; displaying date, time and datetime values (consisting […]

Creating Tables in SPSS

Tables with statistics (means, sums and many more) for metric variables are easily created with DESCRIPTIVES. For reporting such descriptives for groups of cases separately, try MEANS. Frequency distributions and statistics (median, percentiles and more) for categorical variables are generated with FREQUENCIES. Frequencies or percentages for combinations of two or more categorical variables are created with CROSSTABS, which can also run chi-square tests. […]

SPSS – Analyzing Subsets of Cases

SPSS offers three ways for analyzing subsets of cases. After running SPLIT FILE, output tables and charts will show results for subsets of cases separately. Second, you can temporarily FILTER out cases you’d like to exclude from analysis as shown in the screenshot.  Third, you can permanently remove cases from your data with SELECT IF. Analyzing Subsets of Cases SPSS FILTER […]

SPSS with Python – Looping over Scatterplots

The right way for looping over tables, charts and other procedures in SPSS is with Python. We’ll show how to do so on some real world examples. We’ll use alcotest.sav throughout, part of which is shown below. Note that you need to have the SPSS Python Essentials properly installed for running these examples on your own computer. Example 1: Simple Loop over Bar […]

SPSS – Kendall’s Concordance Coefficient W

We had 5 judges taste and rank 6 different beers. The data -shown above- are in beertest.sav. For answering which beer was rated best, a Friedman test would be appropriate because our rankings are ordinal variables. A second question, however, is to what extent do all 5 judges agree on their beer rankings? If our judges don’t agree at […]

SPSS Confidence Intervals for Correlations Tool

Summary What’s the easiest way to obtain confidence intervals for Pearson correlations? Sadly, we couldn’t find these often requested statistics anywhere in SPSS. The best we encountered on the web were some ancient macros that, well… how to say this delicately… didn’t excel in user friendliness. This tutorial therefore proposes a freely downloadable, menu based tool […]

SPSS – Create All Scatterplots Tool

Creating a scatterplot in SPSS is pretty straightforward. However, I sometimes like to take a quick look at all scatterplots among a set of variables. So I created a simple tool that creates all of them in one click. All Scatterplots Tool – Download and Install First off, make sure you have SPSS version 18 or higher with the SPSS Python Essentials properly installed […]

SPSS Correlation Analysis Tutorial

Correlation Test – What Is It? Null Hypothesis Assumptions Correlation Test in SPSS Reporting Correlation Test – What Is It? A (Pearson) correlation is a number between -1 and +1 that indicates to what extent 2 metric variables are linearly related. It’s best understood by looking at some scatterplots. In short, a correlation of -1 indicates a perfect linear descending relation: higher scores on […]