SPSS – What’s the Best Way to Reverse Code Variables?

In SPSS, we sometimes encounter variables that are negatively coded: lower values indicate higher agreement or more positive sentiments. Although this is not really “wrong” in any way, positive coding is more intuitive. Especially when reporting means over variables, most readers naturally expect higher means to indicate something better, not worse. So what’s the best way to reverse code variables? […]

SPSS – Shortening Long Variable Names

A common problem with SPSS data files are unlabeled variables with huge names. These cause several problems: editing and analyzing your data takes too much time and effort; your syntax becomes unreadable and unmanageable; your output looks terrible. The way to go in this case is setting such variable names as labels. Next, set nice and short […]

SPSS Computes Wrong Week Numbers?

While working on data holding a record for each day, I wanted to create some graphs on week level. So I extracted the weeks with XDATE.WEEK but the week numbers returned by SPSS are nonsensical: every week starts on January 1 and most years end up with week 53 holding just 1 day. There’s different standards for week […]

SPSS Command Types

Summary SPSS commands come in three basic types: procedures, transformations and other commands. Understanding this distinction will allow you to get things done in SPSS faster and more efficiently. SPSS Command Types Diagram SPSS Transformations As shown in the figure, the first question is when a command is executed. Some SPSS commands are not carried out […]

SPSS Transformation Commands

Summary SPSS transformation commands (or simply “transformations”) can be loosely defined as commands that are not immediately carried out when you run them. Instead, they are kept in mind by SPSS and executed only when necessary. The table below gives an overview of SPSS’ main tranformation commands. Main SPSS Tranformation Commands COMMAND NAME GOAL TYPICAL USAGE […]

Combine Categorical Variables

Many easy options have been proposed for combining the values of categorical variables in SPSS. However, the real information is usually in the value labels instead of the values. This tutorial proposes a simple trick for combining categorical variables and automatically applying correct value labels to the result. SPSS Combine Categorical Variables Example You may follow along by downloading and opening hospital.sav. Now say […]

SPSS Time Variables Tutorial

Having a solid understanding of what SPSS time variables are, you may find calculations on them surprisingly easy. This tutorial will demonstrate SPSS’ main time functions. However, we’ll also show that we often don’t even need them for getting things done. Throughout this tutorial, keep in mind that SPSS time variables contain time spans in numbers of […]

Convert String Date to SPSS Date Variable

“I’ve a string variable in my data holding dates formatted as ‘01JAN2016’ without separators between the day, month and year components. To make things worse, the month abbreviations are in Dutch and 3 of those differ from their English counterparts. How can I change this string into an SPSS date variable?” Step 1: Add Separators […]

Extract a Year from a Date

Introduction Extracting the year (or any component) from a date is straightforward with the XDATE (“EXtract DATE“) function. Copy-paste-run the syntax presented below for a demonstration of XDATE. SPSS Xdate Syntax Example *1. Create mini test data. data list free/date(edate10). begin data ’01/01/01′ ’12/12/12′ end data. *2. Extract the year. compute year_from_date = xdate.year(date). exe. *3. Hide decimals for […]

Convert Numeric to Date Variable

Summary For time calculations (such as the number of days between two dates) proper date variables are needed. In some cases, the digits of a numeric variable may represent year, month and day. This tutorial shows how to convert this format into an actual date variable. Convert Numbers to SPSS Date Variables In some cases, […]

SPSS Date Variables Basics

SPSS date variables may seem a bit puzzling at first. However, getting things done fast and accurately with SPSS date variables is not hard at all if you understand some basics. This tutorial will walk you through. You can follow along by downloading and opening hospital.sav. SPSS Date Variables – What Are They? First of all, […]

Date Variables

In SPSS, a date is the number of seconds since the year 1582. These are huge numbers but they are still just numbers like somebody’s weight in kilos or the number of cars in some household. The main difference between dates and other variables is that SPSS displays dates with slashes or dots as in “2016/11/07”. Once you fully realize […]

String Variables

String variables are variables that hold zero or more characters such as letters, numbers, spaces, commas and many more. You can’t use numeric functions such as addition or subtraction on string variables. You can, however, extract one or more characters (a substring) from them, glue them together (concatenate) and a couple of other functions. Like so, working […]

SPSS – Merge Categories of Categorical Variable

Summary Merging some categories of a categorical variable in SPSS is not hard if you do it the right way. This tutorial demonstrates just that. We recommend you try the examples for yourself by downloading and opening hotel_evaluation.sav. Right, when doing a routine inspection of this data file, we’ll see that the variable nation has many small categories. This becomes apparent when […]

Recoding Variables in SPSS

Recoding both string and numeric variables in SPSS is usually done with RECODE. Doing so with syntax is way faster than with the menu, especially if you want to recode many variables at once. Note that you’ll often want to apply or adjust some value labels after recoding.Alternatively, string variables can be recoded into numeric variables with AUTORECODE. Doing […]

SPSS Scratch Variables

Definition Scratch variables are temporary helper variables that don’t show up in your data. A variable is a scratch variable if (and only if) its name starts with “#”. SPSS Scratch Variable – Introduction Say we have a data file holding phone numbers. Now we’d like to extract the area codes into a separate variable. […]

SPSS Looping Tutorials

SPSS DO REPEAT – Simple Tutorial & Examples SPSS LOOP – Quick Tutorial & Examples SPSS VECTOR – Quick Tutorial  

Regression over Many Dependent Variables

“I have a data file on which I’d like to carry out several regression analyses. I have four dependent variables, v1 through v4. The independent variables (v5 through v14) are the same for all analyses. How can I carry out these four analyses in an efficient way that would also work for 100 dependent variables?” […]

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