numeric version of concat?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

numeric version of concat?

lts1
Hi SPSSers,
 
Is there a numeric version of Concat?
 
I have four numeric variables which if concatenated produce a unique Id. How can I do this?
 
Thanks in advance.
 
    Best,
        Lisa
 
 
Reply | Threaded
Open this post in threaded view
|

Re: numeric version of concat?

Hector Maletta

Use a formula with multiples of ten. For instance, if you have four variables (x1 to x4), and for a case with values 1, 2, 3 and 4 in those variables, you want a new variable =1234, the general formula would be:

 

COMPUTE 1000*X1 + 100*X2 + 10*X3 + X4.

 

Hector

 

 


From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Lisa T. Stickney
Sent: 10 October 2009 20:07
To: [hidden email]
Subject: numeric version of concat?

 

Hi SPSSers,

 

Is there a numeric version of Concat?

 

I have four numeric variables which if concatenated produce a unique Id. How can I do this?

 

Thanks in advance.

 

    Best,

        Lisa

 

 

Reply | Threaded
Open this post in threaded view
|

Please disregard numeric version of concat?

lts1
In reply to this post by lts1
Hi all,
 
I just found my problem. Sorry to bother you.
 
    Best,
        Lisa
 
 
----- Original Message -----
Sent: Saturday, October 10, 2009 7:07 PM
Subject: numeric version of concat?

Hi SPSSers,
 
Is there a numeric version of Concat?
 
I have four numeric variables which if concatenated produce a unique Id. How can I do this?
 
Thanks in advance.
 
    Best,
        Lisa
 
 
Reply | Threaded
Open this post in threaded view
|

Re: numeric version of concat?

John F Hall
In reply to this post by Hector Maletta
Hector beat me to it!   If your source variables have more than one digit, you'll have to multiply by multiples of 100 or 1000 etc.  If the variables are adjacent in the raw data, you can read them as a single variable with DATA LIST e.g.Instead of:
 
DATA LIST file '.....'
    /records <n>
    / <source record>        x1 to x4 (1-4).
 
followed by  Hector's solution, you could write :
 
DATA LIST file '.....'
    /records <n>
    / <source record>       ID  (1-4).
 
This useful trick with COMPUTE can also be used with RECODE to define new groups. 
 
Here's an example I just ran from a real survey.  The client wanted a new group which combined marital status (v715) with responsibilty for children (v670). 
 
Step 1: Check the source data:
 
freq v670 v715.

RESPONSIBLE FOR CHILDREN

Frequency

Percent

Valid Percent

Cumulative Percent

Valid

Yes

432

30.6

30.6

30.6

No

953

67.5

67.5

98.2

3

26

1.8

1.8

100.0

Total

1411

100.0

100.0

 

MARITAL STATUS

Frequency

Percent

Valid Percent

Cumulative Percent

Valid

SINGLE

526

37.3

37.5

37.5

MARRIED

467

33.1

33.3

70.8

COHABITING

73

5.2

5.2

76.0

SEPARATED

50

3.5

3.6

79.5

DIVORCED

122

8.6

8.7

88.2

WIDOWED

160

11.3

11.4

99.6

OTHER

5

.4

.4

100.0

Total

1403

99.4

100.0

Missing

System

8

.6

Total

1411

100.0

 
Step 2: Create intermediate variable and check it:

compute famstat=v670*10+v715.

freq famstat.

famstat

Frequency

Percent

Valid Percent

Cumulative Percent

Valid

11

88

6.2

6.3

6.3

12

234

16.6

16.7

23.0

13

30

2.1

2.1

25.1

14

23

1.6

1.6

26.7

15

46

3.3

3.3

30.0

16

10

.7

.7

30.7

21

422

29.9

30.1

60.8

22

228

16.2

16.3

77.0

23

43

3.0

3.1

80.1

24

27

1.9

1.9

82.0

25

75

5.3

5.3

87.4

26

147

10.4

10.5

97.9

27

5

.4

.4

98.2

31

16

1.1

1.1

99.4

32

5

.4

.4

99.7

35

1

.1

.1

99.8

36

3

.2

.2

100.0

Total

1403

99.4

100.0

Missing

System

8

.6

Total

1411

100.0

Step 3: Use RECODE to create desired variable:

recode famstat (21 24 25 26=1)(22 23=2)(11 14 15 16=3)(12 13=4)(else=sysmis) .

value labels famstat

    1 'Single: no kids' 2 'Couple: no kids' 3 'Single: + kids' 4 'Couple: + kids' .

freq famstat .

Frequency

Percent

Valid Percent

Cumulative Percent

Valid

Single: no kids

671

47.6

48.9

48.9

Couple: no kids

271

19.2

19.7

68.6

Single: + kids

167

11.8

12.2

80.8

Couple: + kids

264

18.7

19.2

100.0

Total

1373

97.3

100.0

Missing

System

38

2.7

Total

1411

100.0

..et Voilà!

Don't know why formatting of the last two tables is like this: they look fine on the .spo, but they can probably be improved with pivoting, or by exporting to Word first.

Bon dimanche à tous.

John Hall

 

 

----- Original Message -----
Sent: Sunday, October 11, 2009 1:24 AM
Subject: Re: numeric version of concat?

Use a formula with multiples of ten. For instance, if you have four variables (x1 to x4), and for a case with values 1, 2, 3 and 4 in those variables, you want a new variable =1234, the general formula would be:

 

COMPUTE 1000*X1 + 100*X2 + 10*X3 + X4.

 

Hector

 

 


From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Lisa T. Stickney
Sent: 10 October 2009 20:07
To: [hidden email]
Subject: numeric version of concat?

 

Hi SPSSers,

 

Is there a numeric version of Concat?

 

I have four numeric variables which if concatenated produce a unique Id. How can I do this?

 

Thanks in advance.

 

    Best,

        Lisa