# SPSS Tutorials

BASICS REGRESSION T-TEST ANOVA CORRELATION

# SPSS LEAVE Command

## Introduction

When a new variable is calculated, this calculation starts off with a `SYSTEM MISSING` value for each case. Sometimes it's desirable to use the value of the previous case as a starting point. This can be done with the `LEAVE` command.

## Explanation

• When a new variable is calculated, SPSS will run through all cases from top to bottom in the data. This is called a data pass.
• By default, the value of each new case is initialized as a system missing value. LEAVE suppresses this initialization, causing the calculation of each new value to start with the value of the previous case.
• Therefore, `LEAVE` is typically used for calculating running totals over cases. Most of what's accomplished with `LEAVE` can also be done with `LAG`.

## Example: Creating Test Data with Groups

• `INPUT PROGRAM` is a handy command for creating test data. Nested `LOOP` commands can be used for creating groups of cases but the result will contain SYSTEM MISSING values for all but the innermost loops.
• These can be filled (afterwards) in by using the `LAG` function. An alternative here is to use `LEAVE`.
• The syntax below illustrates how this is accomplished.

## SPSS Leave Syntax Example

*Create test data, 5 groups of N = 4.

input program.
loop group = 1 to 5.
leave group.
loop # = 1 to 4.
end case.
end loop.
end loop.
end file.
end input program.
exe.
SPSS Leave Command - Result

# Let me know what you think!

*Required field. Your comment will show up after approval from a moderator.

# This tutorial has 4 comments

• ### By Ruben Geert van den Berg on August 11th, 2016

Hi Kelly! That's right, LEAVE is very rarely used in SPSS -not quite sure why on earth I wrote about it...

However, please note that LEAVE and COMPUTE are commands (basically: stand-alone instructions). LAG, however, is a function (basically a modifier that can only be used within a command or another function.

If you're working with LAG, perhaps take a look at CREATE as well as it creates lags, leads, cumulative sums and many similar functions over cases.

• ### By Kelly Monteleone on August 11th, 2016

Thank you Ruben. I didn't realize that you couldn't use it in a compute function like "lag".

• ### By Ruben Geert van den Berg on August 11th, 2016

Hi Kelly! With very few exceptions, everything that works in older SPSS versions will work in newer versions too. Just to make sure, I tested another LEAVE example in SPSS 24 and it ran fine.

I uploaded it at Create Factorial Design with INPUT PROGRAM and LEAVE. Could you give it a shot and let me know what happens?

• ### By Kelly Monteleone on August 10th, 2016

Leave is not an option in SPSS 23.0 (at least I can't get it to run).