Category: SPSS Data Editing
SPSS Datetime Variables Tutorial
Introduction This tutorial shows how to work proficiently with SPSS datetime variables. You can follow along with it by downloading and opening hospital.sav. SPSS Main Datetime Functions This tutorial will cover the datetime functions outlined in the table below. Most of them apply to SPSS date variables and time variables as well because their values are stored in numbers of […]
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 […]
Time and Datetime Variables
SPSS date, time and datetime variables are shown in a nice and readable format such as “8-Jan-2013 16:56:10”. However, they all contain just numbers of seconds. This may sound daunting at first but soon turns out to make all sorts of time manipulations surprisingly easy. It also implies that most SPSS date functions can be used on date, time and datetime […]
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 […]
Disaggregate Data
Introduction Sometimes, one may start a project with aggregated data, weighted by a frequency variable. In some cases, though, disaggregating such data (creating n rows for a row with frequency n) may be desired. SPSS Syntax Example *1. Create test data. data list free/gender employed frequency. begin data 0 0 5 1 0 2 0 1 8 1 […]
SPSS VARSTOCASES With Labels Tool
Running VARSTOCASES is often necessary for generating nice charts in SPSS. One of the many examples is a stacked bar chart for comparing multiple variables. Sadly, we lose our variable labels when running VARSTOCASES and we really do need those. The solution is a simple tool that generates our VARSTOCASES for us and applies the variable labels of the input variables as value […]
Restructuring Data in SPSS – Overview
SPSS offers several simple ways for restructuring data. VARSTOCASES -short for “variables to cases”- stacks variables on top of each other. Its reverse is CASESTOVARS -short for “cases to variables”. It basically stacks groups of cases behind each other in new variables. AGGREGATE adds summary statistics such as frequencies, sums and means to your data, optionally collapsing cases in the process. […]
Merging Data Files in SPSS
For merging SPSS data files with similar cases but different variables, use MATCH FILES. Make sure your case identifier -if any- doesn’t contain duplicate values and the files are sorted ascendingly on it. The result contains all cases from both files (like a full outer join in SQL).Second, MATCH FILES also performs a table lookup as illustrated below. SPSS […]
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 ADD FILES Command
Summary ADD FILES is an SPSS command that’s mainly used for merging data sources holding similar variables but different cases. (For the same cases but different variables, see MATCH FILES.) A second use is for reordering and/or dropping variables in a single dataset. SPSS Add Files Matches Data Sources on Variable Names SPSS Add Files – Basic Usage The ADD FILES command […]
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 LTRIM Function
Summary SPSS LTRIM (left trim) removes leading spaces from string values. These occur especially when converting numbers to strings by using the string function.* For removing trailing rather than leading spaces, see RTRIM. Results of CONCAT with and without LTRIM SPSS Ltrim Example The syntax below demonstrates a situation where you’ll like to use LTRIM. Running step 1 simply creates a mini dataset. Step 3 uses CONCAT without LTRIM and […]
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 […]
