levesque problem

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

levesque problem

Bruce Colton
This problem seems to contradict the assertion made on p143 in SPSS Programming and Data Management (4th ed.).  The statement is made that consecutive numeric variables can be 'fitted' with a vector for more efficient processing.  I try just that in the simple experiment below, to store age, sex, and height into vec1, vec2, and vec3, and xsave vec1 to vec3.  However, vec1 to vec3 turn up undefined.  I realize that with the execute statement, the vector vec is gone, but don't the variables vec1, vec2, and vec3 remain?  I appreciate any ideas on this.




*  ---why doesn't this work?.
data list free
  /var1 age sex height var5.
begin data
13 4 2 5 3
4 5 6 5 7
7 8 9 7 1
end data.
vector vec=age to height.
do if $casenum=2.
xsave outfile='c:\users\bruce\documents\data_xout18.sav'
  /keep=vec1 to vec3  var1 var5.
end if.
exe.
*  -----running it returns:  undefined variable name: vec1 - then - undefined variable name: vec3.

=====================
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
Reply | Threaded
Open this post in threaded view
|

Re: levesque problem

Albert-Jan Roskam
Hi,

The vector (which you called 'vec') is, or refers to/represents var1 to var5. There are two different 'flavours' of vectors, and it seems that you're confusing them.
Firstly, the command:
vector vec (5).
creates a so-called inline vector that creates the (empty) vars vec1 to vec5.
Secondly,
vector vec = var1 to var5.
creates a 'real' vector; it refers to a constellation of contiguous vars. That's why in e.g. SAS (and Excel) vectors are referred to as arrays.

This allows you to do things like:
vector vec = var1 to var5.
loop #i = 1 to 5.
do if (#i < 5).
if ( vec(#i) = 1 ) vec(#i + 1) = vec(#i).
end if.
end loop.

Cheers!!
Albert-Jan



--- On Thu, 7/24/08, Bruce Colton <[hidden email]> wrote:

> From: Bruce Colton <[hidden email]>
> Subject: levesque problem
> To: [hidden email]
> Date: Thursday, July 24, 2008, 3:09 AM
> This problem seems to contradict the assertion made on p143
> in SPSS Programming and Data Management (4th ed.).  The
> statement is made that consecutive numeric variables can be
> 'fitted' with a vector for more efficient
> processing.  I try just that in the simple experiment
> below, to store age, sex, and height into vec1, vec2, and
> vec3, and xsave vec1 to vec3.  However, vec1 to vec3 turn
> up undefined.  I realize that with the execute statement,
> the vector vec is gone, but don't the variables vec1,
> vec2, and vec3 remain?  I appreciate any ideas on this.
>
>
>
>
> *  ---why doesn't this work?.
> data list free
>   /var1 age sex height var5.
> begin data
> 13 4 2 5 3
> 4 5 6 5 7
> 7 8 9 7 1
> end data.
> vector vec=age to height.
> do if $casenum=2.
> xsave
> outfile='c:\users\bruce\documents\data_xout18.sav'
>   /keep=vec1 to vec3  var1 var5.
> end if.
> exe.
> *  -----running it returns:  undefined variable name: vec1
> - then - undefined variable name: vec3.
>
> =====================
> 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
Reply | Threaded
Open this post in threaded view
|

Re: levesque problem

Oliver, Richard
In reply to this post by Bruce Colton
There are two issues here:

1. The vector elements are specified incorrectly. The documentation states: "Vector element names must always be specified with a subscript in parentheses." That means, for example, that instead of "vec1" you should specify "vec(1)".

2. The documentation on where you can and cannot use vectors is inadequate. The documentation says that vectors can be used in transformations but not procedures. What it should probably say is something like:

"A vector element is an expression and can be used wherever an expression can be used in transformations (in Compute, If, Do if, Loop).  It can be the target of an assignment in a Compute, or If command.  It cannot be used in other commands where a variable name is required.  Specifically, vector elements cannot be used instead of variable names in Recode, Count, Xsave, Do Repeat, or other transformation commands that require variable names but not expressions, and cannot be used in procedure commands.  Vector names (for the whole vector rather than elements) cannot be used anywhere but in the Vector command itself."

And in the next release, that's what the documentation will say.

It's unclear what you are trying to accomplish with vectors and Xsave in this example, so I can't suggest any alternatives other than to replace the vector with the actual variable list.


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Bruce Colton
Sent: Wednesday, July 23, 2008 8:10 PM
To: [hidden email]
Subject: levesque problem

This problem seems to contradict the assertion made on p143 in SPSS Programming and Data Management (4th ed.).  The statement is made that consecutive numeric variables can be 'fitted' with a vector for more efficient processing.  I try just that in the simple experiment below, to store age, sex, and height into vec1, vec2, and vec3, and xsave vec1 to vec3.  However, vec1 to vec3 turn up undefined.  I realize that with the execute statement, the vector vec is gone, but don't the variables vec1, vec2, and vec3 remain?  I appreciate any ideas on this.




*  ---why doesn't this work?.
data list free
  /var1 age sex height var5.
begin data
13 4 2 5 3
4 5 6 5 7
7 8 9 7 1
end data.
vector vec=age to height.
do if $casenum=2.
xsave outfile='c:\users\bruce\documents\data_xout18.sav'
  /keep=vec1 to vec3  var1 var5.
end if.
exe.
*  -----running it returns:  undefined variable name: vec1 - then - undefined variable name: vec3.

=====================
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