Date: Wed, 21 Sep 2005 00:49:59 -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
In-Reply-To: <BF50FFEE.2A96A%healym@earthlink.net>
Content-Type: text/plain; charset="us-ascii"; format=flowed
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
It looks like there's one record containing key labels 'A' and 'B', and
then a second record containing '999' and '999' -- which, therefore,
must also be character values.
>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
>
>And this needs to be duplicated for each row in data set 1. Phew.
I'm not at all sure what it would mean to "duplicate for every row in
data set 1": what would be in those other rows? and what would be put
where, in your data set 2? And data set 2 has a serious problem:
there's no key, so if you change the sort order, you can't change it
back.
Anyway, here's a method; complex, so not that great a one, but it
works:
* -------------------------- .
* Method I: Array and scratch variables .
GET FILE=Data1.
LIST.
List
Notes
|---------------------------|-----------------------|
|Output Created |21 Sep 05 00:44:24 |
|---------------------------|-----------------------|
VALUE1 VALUE2
A B
999 998
Number of cases read: 2 Number of cases listed: 2
GET FILE=Data2.
LIST.
List
Notes
|---------------------------|-----------------------|
|Output Created |21 Sep 05 00:44:25 |
|---------------------------|-----------------------|
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
ADD FILES
/FILE=Data1/IN=Data1
/FILE=Data2/IN=DATA2
/KEEP=Var1 Var2 Var3 ALL.
LIST.
List
Notes
|---------------------------|-----------------------|
|Output Created |21 Sep 05 00:44:25 |
|---------------------------|-----------------------|
VAR1 VAR2 VAR3 VALUE1 VALUE2 DATA1 DATA2
. . A B 1 0
. . 999 998 1 0
1 2 . 0 1
2 1 . 0 1
3 2 1 0 1
3 2 2 0 1
A 0 . 0 1
2 1 3 0 1
2 2 2 0 1
B 0 . 0 1
Number of cases read: 10 Number of cases listed: 10
VECTOR #KEYS(10,A4)
/#VALS(10,A4).
NUMERIC #D1_REC(F2).
VECTOR Data1Val = Value1 TO Value2.
DO IF DATA1 = 1.
. COMPUTE #D1_REC = #D1_Rec+1.
. LOOP #IDX =1 TO 2.
. IF (#D1_REC = 1) #KEYS(#IDX) = Data1Val(#IDX).
. IF (#D1_REC = 2) #VALS(#IDX) = Data1Val(#IDX).
. END LOOP.
END IF.
DO IF DATA2 = 1.
. LOOP #IDX = 1 TO 10.
. IF (VAR1 = #KEYS(#IDX)) VAR1 = #VALS(#IDX).
. END LOOP.
END IF.
LIST.
List
Notes
|---------------------------|-----------------------|
|Output Created |21 Sep 05 00:44:26 |
|---------------------------|-----------------------|
VAR1 VAR2 VAR3 VALUE1 VALUE2 DATA1 DATA2
. . A B 1 0
. . 999 998 1 0
1 2 . 0 1
2 1 . 0 1
3 2 1 0 1
3 2 2 0 1
999 0 . 0 1
2 1 3 0 1
2 2 2 0 1
998 0 . 0 1
Number of cases read: 10 Number of cases listed: 10
SELECT IF DATA2 = 1.
ADD FILES
/FILE=*
/KEEP=VAR1 VAR2 VAR3.
LIST.
List
Notes
|---------------------------|-----------------------|
|Output Created |21 Sep 05 00:44:27 |
|---------------------------|-----------------------|
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