SPSS tutorials

BASICS DATA ANALYSIS T-TEST ANOVA CHI-SQUARE TEST

SPSS RANGE Function – Quick Tutorial

COMPUTE v2 = RANGE(V1,2,4).

SPSS Range Function Result SPSS RANGE Function Result

Summary

SPSSRANGE function is used to evaluate whether or not values are within a given range. Test values equal to the lower or upper boundary are also within the given range. Run the syntax below for a quick demonstration.

SPSS Range Syntax Example

*1. Create couple of cases.

data list free/v1(f1).
begin data
1 2 3 4 5 6
end data.

*2. Check whether value on v2 is between 2 and 4.

compute v2 = range(v1,2,4).
exe.

Notes

RANGE takes three arguments. So in RANGE(A,B,C)

RANGE may return three values:

SPSS Range with Dates and Times

SPSS RANGE can be readily used with date variables and time variables. It should be kept in mind that SPSS dates and times are expressed in numbers of seconds. This implies that you should convert “normal” date and time values into numbers of seconds too. This can be done with the DATE.DMY and TIME.HMS functions as shown in the syntax below.Minutes and seconds default to zero in TIME.HMS. That is, TIME.HMS(18,0,0) may be shortened to TIME.HMS(18).

SPSS Range Syntax Example

*1. Create arrival time dataset.

data list free/arrival(time10).
begin data
10:32:12 12:59:43 16:34:36 17:20:50 18:41:23 23:48:03
end data.

*2. Flag arrivals between noon and 6 PM.

compute arrival_during_afternoon = range(arrival,time.hms(12,0,0),time.hms(18)).
exe.

SPSS Range with Strings

Technically, you can use RANGE for string values too. SPSS basically uses an alphabetical order to determine whether string values are in a given range or not. This can be seen by running SORT CASES as in the syntax example below.

SPSS Range Syntax Example

*1. Create mini dataset.

data list free/v1(a2).
begin data
a b c C cc d D EE e f
end data.

*2. Sort cases.

sort cases by v1.

*3. Flag values between 'C' and 'e'.

compute v2 = range(v1,'C','e').
exe.

Previous tutorial: SPSS Macros

Next tutorial: SPSS RANK Command

Let me know what you think!

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

This tutorial has 5 comments