Search Syntax Files for Expression

Question “I found a variable “v_4” in an old data file and I can’t remember how exactly I created it. The syntax I used got a bit messy, I have different files and they’re in different folders. Is there an easy way to find out which syntax files contain the expression “v_4″?” SPSS Search Syntax […]

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) […]

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 […]

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 […]

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 – 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 LOOP – Quick Tutorial & Examples

LOOP is a command for running one or many SPSS transformation commands repetitively. SPSS LOOP is often used together with VECTOR. An (often) easier alternative is DO REPEAT. There are several ways for looping in SPSS. It depends on the specifics of the situation which one(s) you can use. Note that these options are only available in syntax. An […]

SPSS RTRIM Function

Summary By default, SPSS right pads string values with spaces up to the length of their containing string variables. You don’t usually see this but it may complicate concatenating strings. Such complications are avoided by trimming off trailing spaces using RTRIM (right trim). In Unicode mode, RTRIM is applied automatically but it’s fine to use it anyway. Results of steps 6 and 7 of the […]

SPSS REPLACE Function

Definition SPSS REPLACE replaces a substring in a string by a different (possibly empty) substring. SPSS Replace – Removing Spaces URLs are created from “title” by using REPLACE. The syntax below demonstrates how to do this. We have a dataset holding the titles of web pages and we’d like to convert these to URLs. For one thing, we don’t like spaces in […]

SPSS INDEX Function

Summary The SPSS INDEX function returns the position of the first occurrence of a given expression within a string. If the expression does not occur in the string, it returns a zero. As a rule of thumb, always use it as CHAR.INDEX. The reason for this is explained SPSS Unicode Mode. Note that string values are case sensitive. SPSS Index […]

Create Dictionary Dataset

An often requested feature is to export variable and value labels to Excel. This handy tool creates an SPSS Dataset containing these labels. It can either be be saved as an Excel sheet or further edited in SPSS. SPSS Create Dictionary Dataset Tool – How To Use Make sure you have the SPSS Python Essentials installed. Next, download and […]

SPSS CD Command

A best practice in SPSS is to open and save all files with syntax. Like so, it can be easily seen which syntax was run on which data. One could use the syntax generated by Paste for this but there’s a much shorter and better option. Disadvantages of the Default Syntax Each time you open a data file from […]

Customizing SPSS

One of the many things we love about SPSS is how easily it’s customized and extended with powerful new features. For instance, creating your own toolbar is utterly simple and may save a lot of time and effort. With SPSS version 18, SPSS Extension Bundles were introduced: create completely new SPSS commands, build a menu dialog for them and easily share your […]

Computing Variables in SPSS – Overview

Computing new variables -often as means or sums over other variables- is usually done with COMPUTE. If you want to do so for only some cases but not others, use IF instead. Some alternatives for creating new variables in SPSS are RECODE, AUTORECODE, AGGREGATE and RANK. Computing Variables Tutorials SPSS Missing Values Functions SPSS COMPUTE – Simple Tutorial

SPSS Python Text Replacement Tutorial

A common task in Python is building strings from other strings, especially if we’re creating SPSS syntax. We could simply concatenate strings into larger strings but there’s a nicer way: string replacements with the % sign. Please note that the examples in this tutorial assume Python2.x* and may not run in Python3.x. Python String Replacement with %s *Replace […]

SPSS Python String Tutorial

The most important Python object we’ll deal with are strings. This tutorial presents a quick overview of Python string methods. However, let’s first learn some very basics. Python Strings – Basic Rules Strings may be enclosed by single or double quotes if they don’t contain any line breaks; Strings may always be enclosed by 3 single […]