Posts filed under '5. Coding SPSS Syntax'

Combine two variables into one

2

One of the many questions we got the last few days was from Dana. Dana asked us a question about combining two variables into one:

“Hello, I need to essentially combine two variables that have been
standardized into one new variable.  Data that is present in one variable
is missing on the other and vice versa.  I tried making a new variable and
then recoding missing data so it would pull in the values from the other
variable.  Can you only recode missing values into numbers, or can I pull
an entirely different variable into it?  Basically, how do I combine two
variables into one?  Is there an easier way? Thanks!”

6 comments April 10th, 2007 andris

Recode missing values with Syntax

3.5

Today, Aleksandar sent us the following question:

“I’m having problems to recode system missing values to 0 with syntax
editor. How can I do that?”

In SPSS Syntax, missing values can be addressed via the keywords “sysmis” or “missing”. For this explanation we assume that in addition to the values 1 and 2, there are also values 3 and 4 which are defined as missing values. Please find some syntax below and an explanation of what they do. var2 stands for the variable name we are recoding.

RECODE var2 (missing = 3).

1 comment December 7th, 2006 andris

Recoding with a syntax

3

This week we got a question from Timo.

Is it possible to use syntax when recoding variables? For example, if I
had a variable that included the following values:

Ladybird
Bluebird
Elm
Butterfly

and I wanted to recode any values that included ‘bird’ into a new value
‘bird’, can I do this with the Recode transformation?

To solve to problem the following syntax is an option:

DATA LIST LIST /var1(A15).
BEGIN DATA
Bluebird
Ladybird
Birdwatcher
Butterfly
Elm
END DATA.

STRING newVar(A15).
DO IF INDEX(UPCASE(var1),”BIRD”) > 0 .
- COMPUTE newVar=”BIRD”.
END IF.
EXECUTE.

Add comment August 17th, 2006 mark

Coding editor with SPSS syntax highlighting

I am also writing webpages, and code (X)HTML and PHP by hand. If you code by hand, any code, and also SPSS syntax code, than it is very usefull to have syntax highlighting. Syntax highlighting is a feature of text / code editors that highlights or colourises code. By colourizing code you can very easily recognise types of code.

9 comments March 20th, 2006 andris


Calendar

July 2008
M T W T F S S
« Oct    
 123456
78910111213
14151617181920
21222324252627
28293031  

Posts by Month

Posts by Category