|
Dear listers,
I need to re-arrange some variables in an SPSS file and I am wondering if any of the following can be done through syntax: 1. Move a variable to the end of the data set (I have several variables that need to be moved and there are over 5000 variables in the file, so drag-and-drop method in the Variable view is very tedious and time consuming for this) 2. Insert a new variable after a variable with a specified name 3. Insert 150 new variables after a variable with a specified name I would appreciate any help... Thanks in advance. Tanya ====================To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
|
There are a number of commands which re-order variables.
I would recommend that you compute your new variables first and then reorder them together--it's so much more efficient. Several file related commands have subcommand KEEP--SAVE is the most convenient to use. KEEP keeps variables in the order that you specify them on the subcommand. You can use the TO convention to refer to variables in the current order. If you search for KEEP in HELP, you will find syntax examples. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Tanya Dockendorf Sent: Thursday, October 18, 2007 3:37 PM To: [hidden email] Subject: re-arranging variables using syntax Dear listers, I need to re-arrange some variables in an SPSS file and I am wondering if any of the following can be done through syntax: 1. Move a variable to the end of the data set (I have several variables that need to be moved and there are over 5000 variables in the file, so drag-and-drop method in the Variable view is very tedious and time consuming for this) 2. Insert a new variable after a variable with a specified name 3. Insert 150 new variables after a variable with a specified name I would appreciate any help... Thanks in advance. Tanya ======= To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
|
In reply to this post by Tanya Dockendorf-2
At 05:37 PM 10/18/2007, Tanya Dockendorf wrote:
>there are over 5000 variables in the file, so drag-and-drop method in >the Variable view is very tedious and time consuming for [moving >variables] I should think so. I've had a lot of studies with nowhere near that many *cases*. First, not addressing your question but a general remark: One can be pretty confident that a file with 5,000 variables can be made much easier to work with by restructuring it. Useful techniques, which may be used together, include, - Separating the file into several files by topical groups of variables, and re-joining for analysis as necessary, using MATCH FILES - Where the there are several sets of similar variables, like results of observations at several different times, 'unroll' to put each set in a separate case, giving you many more cases and fewer variables. Second, ViAnn Beadle is correct that the /KEEP subcommand available for SPSS commands including MATCH FILES, ADD FILES, SAVE, and GET, is your best tool. For your situation, to >1. Move a variable to the end of the data set (I have several >variables that need to be moved) To move one variable to the end, suppose the variables in your file are like this: Alpha, Beta, ..., LastBefr, To_Move, FrstAftr, ..., Omega Write your /KEEP= subcommand like this: /KEEP=Alpha TO LastBefr, FrstAftr TO Omega, To_Move, ALL (For safety, end all your /KEEP subcommands with the keyword 'ALL') To move several variables to the end all at once (the recommended way), if your variable list is like Alpha, Beta, ..., LastBef1, To_Move1, FrstAft1, ..., LastBef2, To_Move2, FrstAft1, ..., LastBefn, To_Moven, FrstAftn, ..., Omega write your /KEEP= subcommand like this (I'm breaking onto separate lines for readability) /KEEP=Alpha TO LastBef1, FrstAft1 TO LastBef2, ..., FrstAftn TO Omega, To_Move1, ToMove2, ..., ToMoven, ALL (If you want to change the order of the ToMove variables at the end, just list them in the new order you want.) > 2. Insert a new variable after a variable with a specified name If your variable list is like Alpha, Beta, ..., SpecName, NextName, ..., Omega first create NewVrble with COMPUTE or however you like; then, use a /KEEP subcommand like, /KEEP=Alpha TO SpecName, NewVrbl, NextName TO Omega, ALL If that's all you want to do, you can use the following shorter form, because of how /KEEP works: /KEEP=Alpha TO SpecName, NewVrbl, ALL > 3. Insert 150 new variables after a variable with a specified name Just the same. Create NewVb001 to NewVb150 however you like (but in that order in the file). Then use /KEEP=Alpha TO SpecName, NewVb001 TO NewVb150, NextName TO Omega, ALL or /KEEP=Alpha TO SpecName, NewVb001 TO NewVb150, ALL ................... I suggest using your /KEEP subcommand one of these two ways: First, *save a copy of your file as it is*, in case something goes wrong. If you're creating new variables (as in 2. and 3., above), create those variables first, then save. Then, either SAVE OUTFILE=<file specification> /KEEP=.... That creates a new .SAV file with the variables in the new order OR ADD FILES /FILE=* /KEEP=.... That reorders the variables in the working file, at the cost of reading the whole file. -Good luck and good wishes, Richard ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
|
In reply to this post by ViAnn Beadle
Hi!
KEEPing only the vars that you need is by far the most efficient way, but in the GUI, under utilities, you can also define & use sets of variables. I have never really used this myself, but I think it could be useful in your case. Cheers! Albert-Jan --- ViAnn Beadle <[hidden email]> wrote: > There are a number of commands which re-order > variables. > > I would recommend that you compute your new > variables first and then reorder > them together--it's so much more efficient. > > Several file related commands have subcommand > KEEP--SAVE is the most > convenient to use. KEEP keeps variables in the order > that you specify them > on the subcommand. You can use the TO convention to > refer to variables in > the current order. If you search for KEEP in HELP, > you will find syntax > examples. > > > -----Original Message----- > From: SPSSX(r) Discussion > [mailto:[hidden email]] On Behalf Of > Tanya Dockendorf > Sent: Thursday, October 18, 2007 3:37 PM > To: [hidden email] > Subject: re-arranging variables using syntax > > Dear listers, > I need to re-arrange some variables in an SPSS file > and I am wondering if > any of the following can be done through syntax: > > > 1. Move a variable to the end of the data set (I > have several variables > that need to be moved and there are over 5000 > variables in the file, so > drag-and-drop method in the Variable view is very > tedious and time consuming > for this) > 2. Insert a new variable after a variable with a > specified name > 3. Insert 150 new variables after a variable with > a specified name > > I would appreciate any help... > > Thanks in advance. > Tanya > > ======= > To manage your subscription to SPSSX-L, send a > message to > [hidden email] (not to SPSSX-L), with no > body text except the > command. To leave the list, send the command > SIGNOFF SPSSX-L > For a list of commands to manage subscriptions, send > the command > INFO REFCARD > > ===================== > To manage your subscription to SPSSX-L, send a > message to > [hidden email] (not to SPSSX-L), with no > body text except the > command. To leave the list, send the command > SIGNOFF SPSSX-L > For a list of commands to manage subscriptions, send > the command > INFO REFCARD > Cheers! Albert-Jan ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Did you know that 87.166253% of all statistics claim a precision of results that is not justified by the method employed? [HELMUT RICHTER] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
| Free forum by Nabble | Edit this page |
