LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (November 2003)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 18 Nov 2003 16:39:39 +0100
Reply-To:     "Steiner, Markus" <markus.steiner@uba.de>
Sender:       "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:         "Steiner, Markus" <markus.steiner@uba.de>
Subject:      AW:      Re: Write variable name into new variable
Comments: To: "Marks, Jim" <Jim.Marks@lodgenet.com>
Content-Type: text/plain; charset="iso-8859-1"

Jim,

that's right, I could code the names manualy according my col number, but as I have to run the code over several slightly different data sets, I wanted to avoid to change the code for evey data set but run it automaticly.

Thank you, Markus

-----Ursprüngliche Nachricht----- Von: Marks, Jim [mailto:Jim.Marks@lodgenet.com] Gesendet: Dienstag, 18. November 2003 16:33 An: SPSSX-L@LISTSERV.UGA.EDU Betreff: Re: Write variable name into new variable

Marcus:

It looks like col carries the information you want. Add this to the bottom of your code:

STRING name (a1). IF col EQ 1 name = 'X'. IF col EQ 2 name = 'Y'. IF col Eq 3 name = 'Z'.

ADD FILES FILE = * /KEEP id loc date name col value. EXECUTE.

cheers

Jim Marks Senior Market Analyst LodgeNet Entertainment Corporation

-----Original Message----- From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU]On Behalf Of Steiner, Markus Sent: Tuesday, November 18, 2003 9:17 AM To: SPSSX-L@LISTSERV.UGA.EDU Subject: Write variable name into new variable

Hello,

while partly transposing a data set I would need to write the variable name of some variables into a new variable, so that the information, from which variable are the values after transposition are still available.

Here an example:

Original data

ID loc date x y z 1 N 12.11. 12 22 53 2 W 23.10. 34 11 34 3 N 24.08. 14 31 76

with the folowing code:

DATA LIST FREE / id (N) loc (A) date (EDATE) var1 (N) var2 (N) var3 (N). BEGIN DATA 1 N 12.11.03 12 22 53 2 W 23.10.03 34 11 34 3 N 24.08.03 14 31 76 END DATA.

IF ( MISSING(LAG($CASENUM)) OR id <> LAG(id) ) ROW=1. IF(MISSING(ROW)) ROW=LAG(ROW)+1 . VECTOR VAR=var1 TO var3 . LOOP COL=1 TO 3 . COMPUTE value=VAR(COL). XSAVE OUTFILE 'tmp_flip.sav' / KEEP id loc date row col value . END LOOP. EXECUTE. GET FILE 'tmp_flip.sav'.

it looks like:

ID loc date row col value 1 N 12.11. 1 1 12 1 N 12.11. 1 2 22 1 N 12.11. 1 3 53 2 W 23.10. 1 1 34 2 W 23.10. 1 2 11 2 W 23.10. 1 3 34 3 N 24.08. 1 1 14 3 N 24.08. 1 2 31 3 N 24.08. 1 3 76

and that's what I want:

ID loc date name col value 1 N 12.11. X 1 12 1 N 12.11. Y 2 22 1 N 12.11. Z 3 53 2 W 23.10. X 1 34 2 W 23.10. Y 2 11 2 W 23.10. Z 3 34 3 N 24.08. X 1 14 3 N 24.08. Y 2 31 3 N 24.08. Z 3 76

Any help would be very helpful.

Regards.

Markus


Back to: Top of message | Previous page | Main SPSSX-L page