Date: Wed, 5 May 2004 22:26:32 -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: collect cases
In-Reply-To: <53917C24.61719D3E.001AFF9C@netscape.net>
Content-Type: text/plain; charset="us-ascii"; format=flowed
At 10:18 AM 5/5/2004, ARUN, Ozgur wrote:
>I have a data set like this;
>
>a1 u1 o1 a2 u2 o2 . . . a250 u250 o250
>
>30 45 45 56 58 45 . . . 21 52 34
>40 34 54 23 52 34 . . . 25 63 45
>50 56 49 38 25 65 . . . 52 49 67
>. .
>. .
>
>I wish to collect all cases within all "a" variables under varA, "u"
>variables under varU, and "o" variables under varO.
So, it sounds like you want something like this:
varA varU varO
30 45 45
56 58 45
etc.
That's a good idea a lot of times, but a VERY BAD one unless you have
an identifying variable in the file, to indicate which original case
each record comes from. AND include the index (1-250) of the triplet of
data values.
You can do what you want with CASESTOVARS, I think, but for fun, here's
older logic, using VECTOR/LOOP/XSAVE. The original case number is the
global ID, and the index is the secondary ID. Code is NOT TESTED.
NUMERIC CASE_ID (F5)
/VAR_IDX (F3)
/VARA VARU VARO (F2).
VARIABLE LABELS
CASE_ID 'Original case identifier: $CASENUM from input file'
VAR_IDX 'Position of current set of data, within original case'
VarA 'Value of A-variable, for current case and index'
VarU 'Value of U-variable, for current case and index'
VarO 'Value of O-variable, for current case and index'.
VECTOR DATA_VAL=A1 TO O250.
COMPUTE CASE_ID = $CASENUM.
LOOP VAR_IDX = 1 TO 250.
. COMPUTE #BASE = 3*(VAR_IDX - 1).
. COMPUTE #SUBSCR = #BASE + 1.
. COMPUTE VarA = DATA_VAL(#SUBSCR).
. COMPUTE #SUBSCR = #BASE + 2.
. COMPUTE VarU = DATA_VAL(#SUBSCR).
. COMPUTE #SUBSCR = #BASE + 3.
. COMPUTE VarO = DATA_VAL(#SUBSCR).
. XSAVE OUTFILE='c:\MY_SPSS\COLLECT.SAV'
/KEEP= CASE_ID VAR_IDX VarA VarU VarO.
END LOOP.
EXECUTE /* Here's a case where EXECUTE is needed */.