Merge files

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

Merge files

Bill Wu
I would like merge two files which had different structures.

File A looks like
ID  V1
1    10
1    20
2    30
2    40
3    50
3    60

File B looks like
ID   V2
1     0
2     1
3     2
  I would like to merge V2 into File A and make File A looks like

ID    V1    V2
1    10    0
1    20    0
2    30    1
2    40    1
3    50    2
3    60    2

Your help is appreciated.

Bill Wu
School of Nursing
University at Buffalo

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Merge files

ariel barak
Hi Bill,

Here is tested code. You can paste from the first Data List command all the way down to the List command to see what is going on.

-Ariel

DATA LIST LIST /ID (F8) V1 (F8).
BEGIN DATA
1    10
1    20
2    30
2    40
3    50
3    60
END DATA.
DATASET NAME FileA.
SORT CASES BY ID.

DATA LIST LIST /ID (F8) V2 (F8).
BEGIN DATA
1     0
2     1
3     2
END DATA.
DATASET NAME FileB.
SORT CASES BY ID.

DATASET ACTIVATE FileA.

MATCH FILES /FILE=*
  /TABLE='FileB'
  /BY ID.
EXECUTE.

LIST.

      ID       V1       V2

       1       10        0
       1       20        0
       2       30        1
       2       40        1
       3       50        2
       3       60        2


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

On Thu, May 12, 2011 at 3:08 PM, Bill Wu <[hidden email]> wrote:
I would like merge two files which had different structures.

File A looks like
ID  V1
1    10
1    20
2    30
2    40
3    50
3    60

File B looks like
ID   V2
1     0
2     1
3     2
 I would like to merge V2 into File A and make File A looks like

ID    V1    V2
1    10    0
1    20    0
2    30    1
2    40    1
3    50    2
3    60    2

Your help is appreciated.

Bill Wu
School of Nursing
University at Buffalo

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

Reply | Threaded
Open this post in threaded view
|

Re: Merge files

Daniel J. Robertson
In reply to this post by Bill Wu
Assuming your datasets are named 'FileA' and 'FileB' and FileA is the active dataset:

match files
 /file = *
 /table = 'FileB'
 /by ID .

Note that both datasets will need to be sorted by ID in ascending order.


--
Daniel Robertson
Senior Research and Planning Associate
Institutional Research and Planning
Cornell University / irp.cornell.edu


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Bill Wu
Sent: Thursday, May 12, 2011 4:08 PM
To: [hidden email]
Subject: [SPSSX-L] Merge files

I would like merge two files which had different structures.

File A looks like
ID  V1
1    10
1    20
2    30
2    40
3    50
3    60

File B looks like
ID   V2
1     0
2     1
3     2
  I would like to merge V2 into File A and make File A looks like

ID    V1    V2
1    10    0
1    20    0
2    30    1
2    40    1
3    50    2
3    60    2

Your help is appreciated.

Bill Wu
School of Nursing
University at Buffalo

=====================
To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD