Adding vector

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

Adding vector

Jignesh Sutar-3
Hi,

I'm trying to add a row vector defined by !vars to the example dataset shown below.

DEFINE !vars() abc def ghi jkl !ENDDEFINE.
DATA LIST LIST
 /va1 (F3) var2 (F3).
BEGIN DATA
1 2
3 4
5 6
7 8.
END DATA.

So my final output should look like this


DATA LIST LIST
 /va1 (F3) var2 (F3) VarName(A8).
BEGIN DATA
1 2 'abc'
3 4 'def'
5 6 'ghi'
7 8 'jkl'.
END DATA.


My attempt below fails because I cant get rid of the final semi-colon in the compute statement and am not sure if there is any other way to to achieve this.

DEFINE !vars() abc def ghi jkl !ENDDEFINE.
DATA LIST LIST
 /va1 (F3) var2 (F3).
BEGIN DATA
1 2
3 4
5 6
7 8.
END DATA.
DEFINE !cmd ()
MATRIX.
COMPUTE x={ !DO !i !IN (!EVAL(!vars)) !CONCAT(!QUOTE(!i),';') !DOEND }.
PRINT x.
END MATRIX.
!ENDDEFINE.
SET MPRINT ON.
!CMD.
SET MPRINT OFF.

Help much appreciated.

Jignesh
Reply | Threaded
Open this post in threaded view
|

Re: Adding vector

Jignesh Sutar-3
I eventually gave up with the MATRIX approach and used this as a solution:

DEFINE !vars() abc def ghi jkl !ENDDEFINE.
DATA LIST LIST
 /va1 (F3) var2 (F3).
BEGIN DATA
1 2
3 4
5 6
7 8.
END DATA.

DEFINE !cmd()
STRING varName (A256).
!LET !Count="1"
!DO !i !IN (!EVAL(!vars))
IF ($CASENUM=!LENGTH(!Count)) varName=!QUOTE(!i).
!LET !Count=!CONCAT(!Count,"2")
!DOEND
!ENDDEFINE.

SET MPRINT ON.
!cmd.
SET MPRINT OFF.
LIST.


2009/3/9 Jignesh Sutar <[hidden email]>
Hi,

I'm trying to add a row vector defined by !vars to the example dataset shown below.

DEFINE !vars() abc def ghi jkl !ENDDEFINE.
DATA LIST LIST
 /va1 (F3) var2 (F3).
BEGIN DATA
1 2
3 4
5 6
7 8.
END DATA.

So my final output should look like this


DATA LIST LIST
 /va1 (F3) var2 (F3) VarName(A8).
BEGIN DATA
1 2 'abc'
3 4 'def'
5 6 'ghi'
7 8 'jkl'.
END DATA.


My attempt below fails because I cant get rid of the final semi-colon in the compute statement and am not sure if there is any other way to to achieve this.

DEFINE !vars() abc def ghi jkl !ENDDEFINE.
DATA LIST LIST
 /va1 (F3) var2 (F3).
BEGIN DATA
1 2
3 4
5 6
7 8.
END DATA.
DEFINE !cmd ()
MATRIX.
COMPUTE x={ !DO !i !IN (!EVAL(!vars)) !CONCAT(!QUOTE(!i),';') !DOEND }.
PRINT x.
END MATRIX.
!ENDDEFINE.
SET MPRINT ON.
!CMD.
SET MPRINT OFF.

Help much appreciated.

Jignesh

Reply | Threaded
Open this post in threaded view
|

Re: Adding vector

Art Kendall
In reply to this post by Jignesh Sutar-3
This example syntax  adds a column vector to a data set.
Open a new instance of SPSS.  Copy the syntax below to a syntax file.
Click <run>. Click <all>.
DATA LIST free
 /varname (a8).
BEGIN DATA
abc def ghi jkl
END DATA.
DATASET name vnames.
execute.
DATA LIST LIST
 /va1 (F3) var2 (F3).
BEGIN DATA
1 2
3 4
5 6
7 8.
END DATA.
DATASET name other.
match files file=other /file=vnames.
dataset name together.
LIST .

If this is not what you want to do, please explain in more detail what
and why.

Art Kendall
Social Research Consultants



Jignesh Sutar wrote:

> Hi,
>
> I'm trying to add a row vector defined by !vars to the example dataset
> shown below.
>
> DEFINE !vars() abc def ghi jkl !ENDDEFINE.
> DATA LIST LIST
>  /va1 (F3) var2 (F3).
> BEGIN DATA
> 1 2
> 3 4
> 5 6
> 7 8.
> END DATA.
>
> So my final output should look like this
>
>
> DATA LIST LIST
>  /va1 (F3) var2 (F3) VarName(A8).
> BEGIN DATA
> 1 2 'abc'
> 3 4 'def'
> 5 6 'ghi'
> 7 8 'jkl'.
> END DATA.
>
>
> My attempt below fails because I cant get rid of the final
> semi-colon in the compute statement and am not sure if there is any
> other way to to achieve this.
>
> DEFINE !vars() abc def ghi jkl !ENDDEFINE.
> DATA LIST LIST
>  /va1 (F3) var2 (F3).
> BEGIN DATA
> 1 2
> 3 4
> 5 6
> 7 8.
> END DATA.
> DEFINE !cmd ()
> MATRIX.
> COMPUTE x={ !DO !i !IN (!EVAL(!vars)) !CONCAT(!QUOTE(!i),';') !DOEND }.
> PRINT x.
> END MATRIX.
> !ENDDEFINE.
> SET MPRINT ON.
> !CMD.
> SET MPRINT OFF.
>
> Help much appreciated.
>
> Jignesh

=====================
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
Art Kendall
Social Research Consultants