Moving varaibles using syntax

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Moving varaibles using syntax

Jignesh Sutar-3
Hello,

Is it possible to move variable position using syntax? Using SPSS v15

Thanks in advance
Jignesh
Reply | Threaded
Open this post in threaded view
|

Re: Moving varaibles using syntax

ariel barak
Jignesh,

I found how to do this myself two days ago after finding the topic covered
on Raynald's SPSS Tools
site<http://www.spsstools.net/Syntax/LabelsAndVariableNames/DeleteOrReorderVariableNames.txt>.
Here is the syntax below...


* How to delete or reorder variable names.

* Raynald Levesque 2002/02/09.

DATA LIST LIST /id sex var1 z age.
BEGIN DATA
1 1 1 1 25
2 2 2 2 35
3 1 5 0 65
END DATA.

* TO change the order to the variables to age id sex var1 z.
MATCH FILES FILE=* /KEEP=age ALL.
LIST.

* NOTE: In the above command, ALL means all remaining variables not
previously named.

* Use the following to delete variables var1, z and age.
MATCH FILES FILE=* /DROP=var1 z age.
LIST.



On 9/20/06, Jignesh Sutar <[hidden email]> wrote:

> Hello,
>
> Is it possible to move variable position using syntax? Using SPSS v15
>
> Thanks in advance
> Jignesh
>
Reply | Threaded
Open this post in threaded view
|

Re: Moving varaibles using syntax

Jignesh Sutar-3
Thanks,

Still struggling to try find a solution to the exact problem...

How does one move a variable which is in row 15 initially to row 36??
(by syntax)



On 20/09/06, ariel barak <[hidden email]> wrote:
>
> Jignesh,
>
> I found how to do this myself two days ago after finding the topic covered
> on Raynald's SPSS Tools site. Here is the syntax below...
>
> * How to delete or reorder variable names.

* Raynald Levesque
> 2002/02/09.

DATA LIST LIST /id sex var1 z age.
BEGIN DATA
1 1 1 1 25
2 2 2
> 2 35
3 1 5 0 65
END DATA.

* TO change the order to the variables to age id
> sex var1 z.
MATCH FILES FILE=* /KEEP=age ALL.
LIST.

* NOTE: In the above
> command, ALL means all remaining variables not previously named.

* Use the
> following to delete variables var1, z and age.
MATCH FILES FILE=* /DROP=var1
> z age.
LIST.

>
>
>
> On 9/20/06, Jignesh Sutar <[hidden email] > wrote:
> > Hello,
> >
> > Is it possible to move variable position using syntax? Using SPSS v15
> >
> > Thanks in advance
> > Jignesh
> >
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Moving varaibles using syntax

Scott Czepiel
Jignesh,

It appears as though you are trying to change the value of a variable for
one observation (in row 36) to equal the value of that variable for a
different observation (row 15).  You should look at the recode statement or
if statement to see what criteria you can use to identify the row you wish
to change.

For example, if you only want to change row 36, you can refer to the row
number using the $CASENUM system variable:

if ($CASENUM EQ 36) var1 = 2.
execute.

Be careful when using $CASENUM since it does not always map identically to
what is displayed in the data editor.  It is much safer to have some other
way of identifying the observation you wish to change, and using that in a
recode or if statement.

On 9/20/06, Jignesh Sutar <[hidden email]> wrote:

>
> Thanks,
>
> Still struggling to try find a solution to the exact problem...
>
> How does one move a variable which is in row 15 initially to row 36??
> (by syntax)
>
>
>
> On 20/09/06, ariel barak <[hidden email]> wrote:
> >
> > Jignesh,
> >
> > I found how to do this myself two days ago after finding the topic
> covered
> > on Raynald's SPSS Tools site. Here is the syntax below...
> >
> > * How to delete or reorder variable names.
>
> * Raynald Levesque
> > 2002/02/09.
>
> DATA LIST LIST /id sex var1 z age.
> BEGIN DATA
> 1 1 1 1 25
> 2 2 2
> > 2 35
> 3 1 5 0 65
> END DATA.
>
> * TO change the order to the variables to age id
> > sex var1 z.
> MATCH FILES FILE=* /KEEP=age ALL.
> LIST.
>
> * NOTE: In the above
> > command, ALL means all remaining variables not previously named.
>
> * Use the
> > following to delete variables var1, z and age.
> MATCH FILES FILE=* /DROP=var1
> > z age.
> LIST.
> >
> >
> >
> > On 9/20/06, Jignesh Sutar <[hidden email] > wrote:
> > > Hello,
> > >
> > > Is it possible to move variable position using syntax? Using SPSS v15
> > >
> > > Thanks in advance
> > > Jignesh
> > >
> >
> >
>
Reply | Threaded
Open this post in threaded view
|

Re: Moving varaibles using syntax

Richard Ristow
In reply to this post by Jignesh Sutar-3
At 11:30 AM 9/20/2006, Jignesh Sutar wrote:

>How does one move a variable which is in [position] 15 initially to
>[position] 36?? (by syntax)

First, I hope you do mean variable position. You wrote 'row', which is
often used to mean 'record' or 'case.'

Second, doing what you want is a pain in the neck - though, with SPSS
14 and later, Python can make it a lot easier.

About all you can do is (assuming your 15th variable is named TARGET),

MATCH FILES FILE=*
    /KEEP=Vbl_01 TO Vbl_14,
          Vbl_16 TO Vbl_36,
          TARGET
          ALL.

Replace "Vbl_01" by the name of the first variable in the file;
"Vbl_14" by the name of the 14th, etc.

Yes, you do include the old 36th variable in the list; it will be the
35th, after TARGET is moved to position 36.
Reply | Threaded
Open this post in threaded view
|

Re: Moving varaibles using syntax

Melissa Ives
In reply to this post by Jignesh Sutar-3
Hello,

I am assuming that by 'row #' you mean the row in the Variable View.  I
am also assuming that by requesting this in syntax, simply dragging the
variable over to where you want it is not the solution you prefer.


The way we usually reorder variables is with a save command that
'overwrites' the current dataset, then re-open it.
E.g.

SAVE OUTFILE='C:\myfile.sav'/keep=var1 to var14 var16 to var35 var15
var36 to varn.
GET FILE='C:\myfile.sav'.

You can drop in the list of variables using the variables icon if that
is easier.  You can also specify exactly the order of each individual
variable or use the 'to' command to include multiple vars at once.

Melissa

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Jignesh Sutar
Sent: Wednesday, September 20, 2006 10:30 AM
To: [hidden email]
Subject: Re: [SPSSX-L] Moving varaibles using syntax

Thanks,

Still struggling to try find a solution to the exact problem...

How does one move a variable which is in row 15 initially to row 36??
(by syntax)



On 20/09/06, ariel barak <[hidden email]> wrote:
>
> Jignesh,
>
> I found how to do this myself two days ago after finding the topic
> covered on Raynald's SPSS Tools site. Here is the syntax below...
>
> * How to delete or reorder variable names.

* Raynald Levesque
> 2002/02/09.

DATA LIST LIST /id sex var1 z age.
BEGIN DATA
1 1 1 1 25
2 2 2
> 2 35
3 1 5 0 65
END DATA.

* TO change the order to the variables to age id
> sex var1 z.
MATCH FILES FILE=* /KEEP=age ALL.
LIST.

* NOTE: In the above
> command, ALL means all remaining variables not previously named.

* Use the
> following to delete variables var1, z and age.
MATCH FILES FILE=* /DROP=var1
> z age.
LIST.

>
>
>
> On 9/20/06, Jignesh Sutar <[hidden email] > wrote:
> > Hello,
> >
> > Is it possible to move variable position using syntax? Using SPSS
> > v15
> >
> > Thanks in advance
> > Jignesh
> >
>
>



PRIVILEGED AND CONFIDENTIAL INFORMATION
This transmittal and any attachments may contain PRIVILEGED AND
CONFIDENTIAL information and is intended only for the use of the
addressee. If you are not the designated recipient, or an employee
or agent authorized to deliver such transmittals to the designated
recipient, you are hereby notified that any dissemination,
copying or publication of this transmittal is strictly prohibited. If
you have received this transmittal in error, please notify us
immediately by replying to the sender and delete this copy from your
system. You may also call us at (309) 827-6026 for assistance.
Reply | Threaded
Open this post in threaded view
|

Re: Moving varaibles using syntax

Albert-Jan Roskam
Hi,

The following code is based on Ray's method or
re-arranging a data set.

define alfabet (dir = !charend ('/') / oldnam =
!cmdend).
set mprint = on.
file handle inf/name= !dir + !oldnam.
get file=inf.
n of cases 1.
flip.
sort cases by case_lbl.
!let !oldnam2 = !unquote(!oldnam).
!let !newsps =
!quote(!concat('d:\temp\reorder--',!oldnam2,'.sps')).
do if $casenum=1.
write outfile=!newsps /"get file=inf/keep=".
end if.
write outfile=!newsps /" " case_lbl.
exe.
include file=!newsps.
exe.
variable alignment all (center).
save outfile = !dir +
!quote(!concat('reorder--',!oldnam2,'.sav')).
set mprint = off.
!enddefine.

** macro call(s).
** new sav file (with the prefix 'reorder--') is in
same dir.
** Syntax is saved in d:\temp.
!alfabet dir = "D:\temp\" / oldnam =
"youroldfilename.sav". /


Cheers!
Albert-Jan

--- Melissa Ives <[hidden email]> wrote:

> Hello,
>
> I am assuming that by 'row #' you mean the row in
> the Variable View.  I
> am also assuming that by requesting this in syntax,
> simply dragging the
> variable over to where you want it is not the
> solution you prefer.
>
>
> The way we usually reorder variables is with a save
> command that
> 'overwrites' the current dataset, then re-open it.
> E.g.
>
> SAVE OUTFILE='C:\myfile.sav'/keep=var1 to var14
> var16 to var35 var15
> var36 to varn.
> GET FILE='C:\myfile.sav'.
>
> You can drop in the list of variables using the
> variables icon if that
> is easier.  You can also specify exactly the order
> of each individual
> variable or use the 'to' command to include multiple
> vars at once.
>
> Melissa
>
> -----Original Message-----
> From: SPSSX(r) Discussion
> [mailto:[hidden email]] On Behalf Of
> Jignesh Sutar
> Sent: Wednesday, September 20, 2006 10:30 AM
> To: [hidden email]
> Subject: Re: [SPSSX-L] Moving varaibles using syntax
>
> Thanks,
>
> Still struggling to try find a solution to the exact
> problem...
>
> How does one move a variable which is in row 15
> initially to row 36??
> (by syntax)
>
>
>
> On 20/09/06, ariel barak <[hidden email]>
> wrote:
> >
> > Jignesh,
> >
> > I found how to do this myself two days ago after
> finding the topic
> > covered on Raynald's SPSS Tools site. Here is the
> syntax below...
> >
> > * How to delete or reorder variable names.
>
> * Raynald Levesque
> > 2002/02/09.
>
> DATA LIST LIST /id sex var1 z age.
> BEGIN DATA
> 1 1 1 1 25
> 2 2 2
> > 2 35
> 3 1 5 0 65
> END DATA.
>
> * TO change the order to the variables to age id
> > sex var1 z.
> MATCH FILES FILE=* /KEEP=age ALL.
> LIST.
>
> * NOTE: In the above
> > command, ALL means all remaining variables not
> previously named.
>
> * Use the
> > following to delete variables var1, z and age.
> MATCH FILES FILE=* /DROP=var1
> > z age.
> LIST.
> >
> >
> >
> > On 9/20/06, Jignesh Sutar <[hidden email]
> > wrote:
> > > Hello,
> > >
> > > Is it possible to move variable position using
> syntax? Using SPSS
> > > v15
> > >
> > > Thanks in advance
> > > Jignesh
> > >
> >
> >
>
>
>
> PRIVILEGED AND CONFIDENTIAL INFORMATION
> This transmittal and any attachments may contain
> PRIVILEGED AND
> CONFIDENTIAL information and is intended only for
> the use of the
> addressee. If you are not the designated recipient,
> or an employee
> or agent authorized to deliver such transmittals to
> the designated
> recipient, you are hereby notified that any
> dissemination,
> copying or publication of this transmittal is
> strictly prohibited. If
> you have received this transmittal in error, please
> notify us
> immediately by replying to the sender and delete
> this copy from your
> system. You may also call us at (309) 827-6026 for
> assistance.
>


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com