Hi all
I have been trying to do the following via the Restructure Data Wizzard with no joy - can anyone point me in the right direction ? Current data format ID Brand1 B1Q1 B2Q2 Brand2 B2Q1 B2Q2 Age Gender 1 5 1 2 4 2 1 25 1 2 4 2 2 3 2 1 26 2 3 3 1 2 1 1 1 27 1 I require ID Brand Q1 Q2 Age Gender 1 5 1 2 25 1 1 4 2 1 25 1 2 4 2 2 26 2 2 3 2 1 26 2 3 3 1 2 27 1 3 1 1 1 27 1 Keep well Mark Cape Town |
Hi Mark,
Not tested, but the principle should be correct: Save outf = file1 /rename ( Brand1 B1Q1 B1Q2 = Brand Q1 Q2) /drop Brand2 B2Q1 B2Q2 . Save outf = file2 /rename ( Brand2 B2Q1 B2Q2 = Brand Q1 Q2) /drop Brand1 B1Q1 B1Q2 . Get file = file1. Add files file = * /file = file2 /by id. Exe. Hope this helps. Jan -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Mark Webb Sent: Thursday, March 01, 2007 1:21 PM To: [hidden email] Subject: VarsToCases Help Hi all I have been trying to do the following via the Restructure Data Wizzard with no joy - can anyone point me in the right direction ? Current data format ID Brand1 B1Q1 B2Q2 Brand2 B2Q1 B2Q2 Age Gender 1 5 1 2 4 2 1 25 1 2 4 2 2 3 2 1 26 2 3 3 1 2 1 1 1 27 1 I require ID Brand Q1 Q2 Age Gender 1 5 1 2 25 1 1 4 2 1 25 1 2 4 2 2 26 2 2 3 2 1 26 2 3 3 1 2 27 1 3 1 1 1 27 1 Keep well Mark Cape Town |
In reply to this post by Mark Webb-3
Yes it is possible to achieve it also with varstocases. The syntax is:
VARSTOCASES /MAKE brand FROM Brand1 Brand2 /MAKE q1 FROM B1Q1 B2Q1 /MAKE q2 FROM B1Q2 B2Q2 /KEEP = ID Age Gender /NULL = KEEP. Greetings Jan -----Original Message----- From: Mark Webb [mailto:[hidden email]] Sent: Thursday, March 01, 2007 1:50 PM To: Spousta Jan Subject: Re: Re: VarsToCases Help Thanks for the prompt response [as usual] ! I'm currently doing this, but in a more round about way - was just thinking if could be done via VARSTOCASES. Thanks Mark ----- Original Message ----- From: "Spousta Jan" <[hidden email]> To: <[hidden email]> Sent: Thursday, March 01, 2007 2:35 PM Subject: Re: VarsToCases Help > Hi Mark, > > Not tested, but the principle should be correct: > > Save outf = file1 /rename ( Brand1 B1Q1 B1Q2 = Brand Q1 Q2) > /drop Brand2 B2Q1 B2Q2 . > Save outf = file2 /rename ( Brand2 B2Q1 B2Q2 = Brand Q1 Q2) > /drop Brand1 B1Q1 B1Q2 . > Get file = file1. > Add files file = * /file = file2 /by id. > Exe. > > Hope this helps. > > Jan > > > -----Original Message----- > From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf > Mark Webb > Sent: Thursday, March 01, 2007 1:21 PM > To: [hidden email] > Subject: VarsToCases Help > > Hi all > I have been trying to do the following via the Restructure Data Wizzard > with no joy - can anyone point me in the right direction ? > > Current data format > > ID Brand1 B1Q1 B2Q2 Brand2 B2Q1 B2Q2 Age Gender > 1 5 1 2 4 2 1 > 25 1 > 2 4 2 2 3 2 1 > 26 2 > 3 3 1 2 1 1 1 > 27 1 > > I require > > ID Brand Q1 Q2 Age Gender > 1 5 1 2 25 1 > 1 4 2 1 25 1 > 2 4 2 2 26 2 > 2 3 2 1 26 2 > 3 3 1 2 27 1 > 3 1 1 1 27 1 > > Keep well > Mark > Cape Town > > __________ NOD32 2085 (20070228) Information __________ > > This message was checked by NOD32 antivirus system. > http://www.eset.com > > |
In reply to this post by Mark Webb-3
At 07:20 AM 3/1/2007, Mark Webb wrote:
>I have been trying to do the following via the Restructure Data >Wizzard with no joy - can anyone point me in the right direction ? > >Current data format [listed below] > >I require > >ID Brand Q1 Q2 Age Gender >1 5 1 2 25 1 >1 4 2 1 25 1 >2 4 2 2 26 2 >2 3 2 1 26 2 >3 3 1 2 27 1 >3 1 1 1 27 1 SPSS 15 draft output <WRR:not saved separately>. It does put Age and Gender after ID, instead of at the end of the list. Discussion follows I clicked up the VARSTOCASES in the Restructure Wizard as follows: Menu Data>Restructure... Panel 1: Select "Restructure selected variables into cases" Panel 2: "How many variable groups?" Select "More than 1" Enter 3 Panel 3: "Case group identifier" Select "Use selected variable" Move into box: ID "Target variable:" drop-down list - Change 'trans1' to 'Brand' Move into box: Brand1 Brand2 - Change 'trans2' to 'Q1' Move into box: B1Q1 B2Q1 - Change 'trans3' to 'Q2' Move into box: B1Q2 B2Q2 "Fixed variables:" Move into box: Age Gender Panel 4: "Create Index Variables" Select None Panel 5: "Options" Accept all defaults LIST. List |-----------------------------|---------------------------| |Output Created |01-MAR-2007 09:52:07 | |-----------------------------|---------------------------| ID Brand1 B1Q1 B1Q2 Brand2 B2Q1 B2Q2 Age Gender 1 5 1 2 4 2 1 25 1 2 4 2 2 3 2 1 26 2 3 3 1 2 1 1 1 27 1 Number of cases read: 3 Number of cases listed: 3 VARSTOCASES /MAKE Brand FROM Brand1 Brand2 /MAKE Q1 FROM B1Q1 B2Q1 /MAKE Q2 FROM B1Q2 B2Q2 /KEEP = ID Age Gender /NULL = KEEP. Notes |----------------------------|---------------------------| |Output Created |01-MAR-2007 10:06:51 | |----------------------------|---------------------------| Generated Variables |-----|------| |Name |Label | |-----|------| |Brand|<none>| |Q1 |<none>| |Q2 |<none>| |-----|------| Processing Statistics |-------------|-| |Variables In |9| |Variables Out|6| |-------------|-| LIST. List |-----------------------------|---------------------------| |Output Created |01-MAR-2007 10:07:12 | |-----------------------------|---------------------------| ID Age Gender Brand Q1 Q2 1 25 1 5 1 2 1 25 1 4 2 1 2 26 2 4 2 2 2 26 2 3 2 1 3 27 1 3 1 2 3 27 1 1 1 1 Number of cases read: 6 Number of cases listed: 6 =================== APPENDIX: TEST DATA =================== DATA LIST LIST/ ID Brand1 B1Q1 B1Q2 Brand2 B2Q1 B2Q2 Age Gender (9F3). BEGIN DATA 1 5 1 2 4 2 1 25 1 2 4 2 2 3 2 1 26 2 3 3 1 2 1 1 1 27 1 END DATA. |
In reply to this post by Mark Webb-3
At 07:20 AM 3/1/2007, Mark Webb wrote:
>I have been trying to do the following via the Restructure Data Wizard > >Current data format > ID Brand1 B1Q1 B1Q2 Brand2 B2Q1 B2Q2 Age Gender > > 1 5 1 2 4 2 1 25 1 > 2 4 2 2 3 2 1 26 2 > 3 3 1 2 1 1 1 27 1 > >I require > ID Age Gender Brand Q1 Q2 > > 1 25 1 5 1 2 > 1 25 1 4 2 1 > 2 26 2 4 2 2 > 2 26 2 3 2 1 > 3 27 1 3 1 2 > 3 27 1 1 1 1 For completeness: there've been solutions posted using SAVE/SAVE/ADD FILES, and using VARSTOCASES. A variation on the former is XSAVE instead of SAVE, requiring only one scratch file and (if that matters) only one pass through the original data. This is SPSS 15 draft output, inaccurate warning message and all. <WRR: This version saved> LIST. List |-----------------------------|---------------------------| |Output Created |01-MAR-2007 23:11:03 | |-----------------------------|---------------------------| ID Brand1 B1Q1 B1Q2 Brand2 B2Q1 B2Q2 Age Gender 1 5 1 2 4 2 1 25 1 2 4 2 2 3 2 1 26 2 3 3 1 2 1 1 1 27 1 Number of cases read: 3 Number of cases listed: 3 NUMERIC Brand Q1 Q2 (F3). LOOP #Brand# = 1 TO 2. . DO IF #Brand# EQ 1. . COMPUTE Brand = Brand1. . COMPUTE Q1 = B1Q1. . COMPUTE Q2 = B1Q2. . ELSE IF #Brand# EQ 2. . COMPUTE Brand = Brand2. . COMPUTE Q1 = B2Q1. . COMPUTE Q2 = B2Q2. . END IF. . XSAVE OUTFILE=FILE1 >Warning # 142. Command name: XSAVE >LOOP has no effect on this command. /KEEP=ID Brand Q1 Q2 Age Gender. END LOOP. EXECUTE. GET FILE=File1. LIST. List |-----------------------------|---------------------------| |Output Created |01-MAR-2007 23:16:42 | |-----------------------------|---------------------------| C:\Documents and Settings\Richard\My Documents \Temporary\SPSS\2007-03-01 Webb - VarsToCases Help.SAV ID Brand Q1 Q2 Age Gender 1 5 1 2 25 1 1 4 2 1 25 1 2 4 2 2 26 2 2 3 2 1 26 2 3 3 1 2 27 1 3 1 1 1 27 1 Number of cases read: 6 Number of cases listed: 6 =================================== APPENDIX: FILE HANDLE AND TEST DATA =================================== FILE HANDLE File1 /NAME='C:\Documents and Settings\Richard\My Documents\Temporary\SPSS\' + '2007-03-01 Webb - VarsToCases Help' + '.SAV'. DATA LIST LIST/ ID Brand1 B1Q1 B1Q2 Brand2 B2Q1 B2Q2 Age Gender (9F3). BEGIN DATA 1 5 1 2 4 2 1 25 1 2 4 2 2 3 2 1 26 2 3 3 1 2 1 1 1 27 1 END DATA. |
Free forum by Nabble | Edit this page |