Transform variable into new variables

Moderators: statman, Analyst Techy, andris, Fierce, GerineL, Smash

simonspss
Posts: 3
Joined: Fri Apr 13, 2012 12:39 pm

Transform variable into new variables

Postby simonspss » Fri Apr 13, 2012 12:57 pm

Hi!

I've a problem, I'm quite new to spss and I'm about to write - a for me - complex syntax.

I've a variable called A02. The variable contain values such as "B001", "C059" and "A004".

The syntax need to do the following:
First I manually create three variables called "A", "B" and "C", the syntax should copy the values from varriable A02 in to the new variables, for example, value "B001" should be copied to variable "B", value "C059" to variable "C" and vice verca. And the first character should also be removed from the value.

Are you following me?

I handle php and java programming, but have no knowledge of spss syntax, so...
Please help me in the right direction.

Regards
Simon
apeape
Posts: 56
Joined: Mon May 02, 2011 6:07 pm

Re: Transform variable into new variables

Postby apeape » Fri Apr 13, 2012 2:40 pm

Here you go:

Code: Select all

**sample data.
data list list / A02 (a10).
begin data.
B001
C059
A004
end data.

comp #y=number(substr(A02,2,3),f8). 
numeric A B C (n3).  /** remove this line if you don't want to keep leading zeroes.
if index(A02, "A")>0 A=#y.
if index(A02, "B")>0 B=#y.
if index(A02, "C")>0 C=#y.
exe.
simonspss
Posts: 3
Joined: Fri Apr 13, 2012 12:39 pm

Re: Transform variable into new variables

Postby simonspss » Sat Apr 14, 2012 5:48 am

apeape wrote:Here you go:

Code: Select all

**sample data.
data list list / A02 (a10).
begin data.
B001
C059
A004
end data.

comp #y=number(substr(A02,2,3),f8). 
numeric A B C (n3).  /** remove this line if you don't want to keep leading zeroes.
if index(A02, "A")>0 A=#y.
if index(A02, "B")>0 B=#y.
if index(A02, "C")>0 C=#y.
exe.
Thanks! I'll examine and try it out next Monday.

Who is online

Users browsing this forum: No registered users and 1 guest

cron