5
1 Data Manipulation and Data Management Day 1, Session IV M. Amir Hossain, Ph.D. January 17, 2016 Transformation Expressions Arithmetic Operations: Following arithmetic operators are available: + Addition. - Subtraction. * Multiplication. / Division. ** Exponentiation.

SPSS

Embed Size (px)

Citation preview

Page 1: SPSS

1

Data Manipulation and Data Management Day 1, Session IV

M. Amir Hossain, Ph.D.

January 17, 2016

Transformation Expressions

Arithmetic Operations: Following arithmetic operators

are available:

+ Addition.

- Subtraction.

* Multiplication.

/ Division.

** Exponentiation.

Page 2: SPSS

2

Transformation Expressions

No two operators can appear consecutively.

Arithmetic operators cannot be implied. For example,

(VAR1)(VAR2) is not a legal specification; you must specify

VAR1*VAR2.

To improve readability, blanks (not commas) can be inserted

before and after an operator.

To form complex expressions, you can use variables, constants,

and functions with arithmetic operators.

Transformation Expressions

The order of execution is functions first, then

exponentiation, then multiplication, division, and

unary, and then addition and subtraction.

Operators at the same level are executed from left to

right.

To override the order of operation, use parentheses.

Execution begins with the innermost set of

parentheses and progresses out.

Page 3: SPSS

3

A relation is a logical expression that compares two values using

a relational operator. Relational operators are:

EQ or = Equal to.

NE or ~= ¬ = or <> Not equal to.

LT or < Less than.

LE or <= Less than or equal to.

GT or > Greater than.

GE or >= Greater than or equal to.

Relational Operators

Data Manipulation Commands

COMPUTE

• COMPUTE target variable = expression

Overview

• COMPUTE creates new numeric variables or modifies the

values of existing variables. The variable named on the left of

the equal sign is the target variable. The variables, constants,

and functions on the right side of the equal sign form an

assignment expression.

Page 4: SPSS

4

Data Manipulation Commands Examples

• COMPUTE INCREMENT=SALARY-SALBEGIN.

• EXECUTE.

• COMPUTE PINCREM=(INCREMENT/SALBEGIN)*100.

• EXECUTE.

• COMPUTE RAISE=SALARY*0.12.

• EXECUTE.

• COMPUTE NEWSAL1 = SALARY + SALARY*0.10

• EXECUTE.

• COMPUTE NEWSAL2 = SALARY + SALBEGIN*0.10 + EDUC*10

• EXECUTE.

RECODE

RECODE varlist (value list =value)...(value list=value) [INTO varlist] [/varlist...]

Input keywords: LO, LOWEST, HI, HIGHEST, THRU, MISSING, SYSMIS,

ELSE

Output keywords: COPY, SYSMIS

Overview:

• RECODE changes, rearranges, or consolidates the values of an existing

variable. RECODE can be executed on a value-by-value basis or for a

range of values. Where it can be used, RECODE is much more efficient

that the series of IF commands that produce the same transformation.

With RECODE, you must specify the new values.

Page 5: SPSS

5

INTO keyword

INTO specifies a target variable to receive recoded values from the original , or source variables. Source variable remain unchanged after the recode. INTO must follow the value specification for the source variables that are being recoded in to the target variables. The number of target variable must equal the number of source variables. Example RECODE SALARY (LO THRU 50000=1)(50001 THRU 75000=2)(75001 THRU HI=3) INTO SALCAT1. EXECUTE.