LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (April 2004)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 20 Apr 2004 16:42:02 -0400
Reply-To:     Richard Ristow <wrristow@mindspring.com>
Sender:       "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:         Richard Ristow <wrristow@mindspring.com>
Subject:      Re: Joining two numeric variables
Comments: To: Don Baker <DRRALPH@OU.EDU>
In-Reply-To:  <200404201710.i3KHAJh04429@listserv.cc.uga.edu>
Content-Type: text/plain; charset="us-ascii"; format=flowed

At 01:10 PM 4/20/2004, Don Baker wrote:

>I want to join (concatenate) the values of two numeric variables into >a new variable. One variable is a four digit coalition site number >and the other is a student id number. By joining the two variables I >will be able to create a set of unique id numbers across several >coalition sites.

First, consider not doing it. Most SPSS commands that use a key (SPLIT FILES, MATCH FILES, AGGREGATE) use a multiple-variable key quite comfortably; combining to a single variable buys you very little. (RANK may be an exception, however; its documentation says, "To organize ranks into subgroups, specify keyword BY followed by the variable whose values determine the subgroups.The working data file does not have to be sorted by this variable." Note 'variable', in the singular.)

Second, you've had two suggestions to do it using string variables. It is also often done by arithmetic on numeric variables; see example below. It assumes that student IDs are 6 digits long; adjust as necessary. (I'm taking the coalition site number as 'more significant' than the student ID, so it goes at the high end -- the 'left' -- of the combined number.)

"NEW_ID1" and "NEW_ID2" are identical, except for different formats; "NEW_ID2" uses N format to display with leading zeroes. Code assumes that student IDs are 6 digits long; adjust as necessary. SPSS draft output:

DATA LIST LIST / SITE_NO (F4) STDT_ID (F6). BEGIN DATA. 17 123456 17 23456 17 101 1001 987654 1001 87654 1001 202 END DATA.

NUMERIC NEW_ID1 (F10) /NEW_ID2 (N10).

COMPUTE NEW_ID1 = SITE_NO*1E6 + STDT_ID. COMPUTE NEW_ID2 = SITE_NO*1E6 + STDT_ID. LIST.

List SITE_NO STDT_ID NEW_ID1 NEW_ID2

17 123456 17123456 0017123456 17 23456 17023456 0017023456 17 101 17000101 0017000101 1001 987654 1001987654 1001987654 1001 87654 1001087654 1001087654 1001 202 1001000202 1001000202

Number of cases read: 6 Number of cases listed: 6


Back to: Top of message | Previous page | Main SPSSX-L page