Date: Thu, 29 Apr 1999 12:30:04 -0500
Reply-To: "Matheson, David" <davidm@SPSS.COM>
Sender: "SPSSX(r) Discussion" <SPSSX-L@UGA.CC.UGA.EDU>
From: "Matheson, David" <davidm@SPSS.COM>
Subject: Re: Transposing data (from many cases to one case)
Robert,
Without seeing your implementation of Raynald's approach and the resulting
error statements, I can't be positive in my diagnosis. However, if you had
defined all the variables as string in your data list, as you do in your
solution, then the job would certainly fail. The loop index variable, i.e.
the 'element' inside parentheses in 'compute element(element)', must be
numeric. Then Raynald's code will work.
Just in case your decision to read all 3 variables as strings was due to a
difficulty in isolating the string format to the last variable in free
format, the following DATA LIST shows you how to do this.
data list free / case element * data (a1) .
The * before DATA keeps SPSS from trying to apply the a1 format to preceding
variables.
I would avoid using DATA and CASE as variable names, though, as each word is
a part of some command names and a keyword in other commands.
Also, you can combine the STRING and VECTOR commands into what the Syntax
Reference Guide calls a short form vector command, which creates the new
variables as well as collecting them in a vector:
vector element(7,a1) .
I hope this helps.
David Matheson
SPSS Technical Support
-----Original Message-----
From: Robert D. Garvin [mailto:rdgarvin@EROLS.COM]
Sent: Thursday, April 29, 1999 10:56 AM
To: SPSSX-L@UGA.CC.UGA.EDU
Subject: Re: Transposing data (from many cases to one case)
Raynald,
I was interested in your use of vector as it's not one that I've used
before.
I tried your example, but I kept getting errors and I'm not sure why. I'm
using ver 8.0.
I've made a few revisions to your example and here's what I came up with.
If anyone can explain why Raynald's didn't work for me and this one does,
I'd appreciate it.
Thanks, Robert.
Data list records=1 free
/1 CASE (A)
ELEMENT (A)
DATA (A) .
BEGIN DATA
1 2 X
1 4 Y
1 5 P
2 1 Q
2 2 R
2 3 S
2 7 J
3 1 F
3 3 G
3 6 H
3 7 I
END DATA.
*-------------------------------------*.
STRING ELEMENT1 to ELEMENT7 (A1).
VECTOR E2 = ELEMENT1 to ELEMENT7.
LOOP #I = 1 TO 7.
+ IF ( NUMBER(ELEMENT,F1.0) = #I ) E2(#I) = DATA.
END LOOP.
EXECUTE.
*------------*.
AGGREGATE OUTFILE *
/BREAK case
/ELEMENT1 TO ELEMENT7 = MAX (ELEMENT1 TO ELEMENT7).
*-------------*.
At 07:51 PM 4/28/99 -0400, you wrote:
>Hi Marcelo and list members!
>
>This does what you are looking for:
>
>STRING ELEMENT1 to ELEMENT7 (A1).
>VECTOR ELEMENT=ELEMENT1 to ELEMENT7.
>COMPUTE ELEMENT(ELEMENT)=DATA.
>
>AGGREGATE OUTFILE *
> /BREAK case
> /ELEMENT1 TO ELEMENT7 = MAX (ELEMENT1 TO ELEMENT7).
>
>Regards
>
>Raynald Levesque rlevesque@videotron.ca
>
>
>----- Original Message -----
>From: Marcelo Simas <simas@WEB4U.COM.BR>
>Newsgroups: bit.listserv.spssx-l
>To: <SPSSX-L@UGA.CC.UGA.EDU>
>Sent: Wednesday, April 28, 1999 7:16 PM
>Subject: Transposing data
>
>
>> Dear colleges,
>> I have a serious problem. I'm an extension course student, and
>to
>> complete my thesis I have to deal with a huge amount of data. In some
step
>> of the handling them I have this situation:
>>
>> CASE ELEMENT DATA
>> 1 2 X
>> 1 4 Y
>> 1 5 P
>> 2 1 Q
>> 2 2 R
>> 2 3 S
>> 2 7 J
>> 3 1 F
>> 3 3 G
>> 3 6 H
>> 3 7 I
>> ... ... ...
>>
>> And what I need is:
>>
>> CASE ELEMENT1 ELEMENT2 ELEMENT3 ELEMENT4 ELEMENT5 ELEMENT6 ELEMENT7
>> 1 X Y P
>> 2 Q R S
>J
>> 3 F G H
>I
>> ...
>>
>> The original matrix isn't a square one, the number of elements
>vary
>> through the cases.
>> I have a SPSS for Windows and have tried to do it by the
transpose
>> command, as it's obvious it hasn't worked. I have very little experience
>> with the Syntax method of operation, but I think to be possible do what I
>> need trough Syntax.
>> If any one can help me I'll be very glad.
>> Thank's in advance.
>> Marcelo Simas
>
Robert D. Garvin, M.A.
Analyst I: Research & Evaluation
Div. Family Health Services
NJ Dept. of Health & Senior Services
voice (609) 292-5656
fax (609) 292-3580
email rdgarvin@erols.com
|