Date: Wed, 21 Sep 2005 01:09:31 -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: Tough data setup
Content-Type: text/plain; charset="us-ascii"; format=flowed
Second method:
At 02:04 AM 9/17/2005, Michael Healy wrote:
>I have two data sets. One data set has a set of within-subject
>responses. The other data set is basically a multi-row/multi-column
>template which I need to populate certain cells with--it is a template
>which applies to every subject.
Sure. Where would we be, without coding exercises?
>A simplified example:
>Data set 1:
>A B
>999 998
>
>Data set 2:
>1 2
>2 1
>3 2 1
>3 2 2
>A 0
>2 1 3
>2 2 2
>B 0
>
>Goal:
>1 2
>2 1
>3 2 1
>3 2 2
>999 0
>2 1 3
>2 2 2
>998 0
This method is nicer. It requires that Dataset1 be transposed, however.
And our Dataset2 has no sort key, so you can't detect errors in sort
order, or re-sort. This code creates variable ORIG_ORD for that
purpose.
* ........................................ .
* Method II: MATCH FILES .
GET FILE=DATA1B.
LIST.
List
Notes
|---------------------------|-----------------------|
|Output Created |21 Sep 05 01:02:09 |
|---------------------------|-----------------------|
KEY VALUE
A 999
B 998
Number of cases read: 2 Number of cases listed: 2
GET FILE=DATA2.
LIST.
List
Notes
|---------------------------|-----------------------|
|Output Created |21 Sep 05 01:02:10 |
|---------------------------|-----------------------|
VAR1 VAR2 VAR3
1 2 .
2 1 .
3 2 1
3 2 2
A 0 .
2 1 3
2 2 2
B 0 .
Number of cases read: 8 Number of cases listed: 8
COMPUTE Orig_Ord = $CASENUM.
FORMATS Orig_Ord (F4).
SORT CASES BY VAR1.
MATCH FILES
/FILE=*
/FILE=DATA1B
/RENAME=(KEY=VAR1)
/IN=MATCHED
/BY VAR1.
. /**/ EXECUTE.
FILE *
KEY: 2
>Warning # 5132
>Duplicate key in a file. The BY variables do not uniquely identify
each
>case on the indicated file. Please check the results carefully.
. /**/ LIST.
List
Notes
|---------------------------|-----------------------|
|Output Created |21 Sep 05 01:02:12 |
|---------------------------|-----------------------|
VAR1 VAR2 VAR3 ORIG_ORD VALUE MATCHED
1 2 . 1 0
2 1 . 2 0
2 1 3 6 0
2 2 2 7 0
3 2 1 3 0
3 2 2 4 0
A 0 . 5 999 1
B 0 . 8 998 1
Number of cases read: 8 Number of cases listed: 8
IF (MATCHED = 1) VAR1 = VALUE.
SORT CASES BY Orig_Ord.
LIST.
List
Notes
|---------------------------|-----------------------|
|Output Created |21 Sep 05 01:02:13 |
|---------------------------|-----------------------|
VAR1 VAR2 VAR3 ORIG_ORD VALUE MATCHED
1 2 . 1 0
2 1 . 2 0
3 2 1 3 0
3 2 2 4 0
999 0 . 5 999 1
2 1 3 6 0
2 2 2 7 0
998 0 . 8 998 1
Number of cases read: 8 Number of cases listed: 8
ADD FILES
/FILE=*
/KEEP=VAR1 VAR2 VAR3.
LIST.
List
Notes
|---------------------------|-----------------------|
|Output Created |21 Sep 05 01:02:13 |
|---------------------------|-----------------------|
VAR1 VAR2 VAR3
1 2 .
2 1 .
3 2 1
3 2 2
999 0 .
2 1 3
2 2 2
998 0 .
Number of cases read: 8 Number of cases listed: 8