Data moving

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

Data moving

Samir Omerovic
Hi to all,



Does anybody know if this is possible to do in SPSS:



Let's say I have the following file:



ID         V1        V2        V3        V4

1          1                      3          1

2                      5                      6

3          1          1                      2

4                                  2          1

5          6                                  1





And I would like to get this file:





ID         V1        V2        V3        V4

1          1          3          1

2          5          6

3          1          1          2

4          2          1

5          6          1



So basically I would like to remove all the empty places and move the entries to the left.



So does anybody have an idea on how to do this?



Thanks in advance



Samir



GfK BH
Centar za istrazivanje trzista i javnog mnijenja d.o.o.

Samir Omerovic
Istrazivac/Researcher

71000 Sarajevo, Skenderija 44
BA, Bosna i Hercegovina
Tel. +387 33 550300
Fax. +387 33 444226
www.gfk.ba
www.gfk.com
Reply | Threaded
Open this post in threaded view
|

Re: Data moving

vlad simion
Hi Samir,

i'm not sure is the most elegant solution, but, try this:

new file.
data list /id 1 v1 2 v2 3 v3 4 v4 5.
begin data
11 2 3
2 34
3 345
41234
end data.

compute j=0.
exe.
vector v = v1 to v4 / tmp(4).
loop #i = 1 to 4.
if ~miss(v(#i)) j=j+1.
if ~miss(v(#i)) tmp(j)=v(#i).
end loop.
exe.

HTH,

Vlad


On 6/25/07, Samir Omerović <[hidden email]> wrote:

>
> Hi to all,
>
>
>
> Does anybody know if this is possible to do in SPSS:
>
>
>
> Let's say I have the following file:
>
>
>
> ID         V1        V2        V3        V4
>
> 1          1                      3          1
>
> 2                      5                      6
>
> 3          1          1                      2
>
> 4                                  2          1
>
> 5          6                                  1
>
>
>
>
>
> And I would like to get this file:
>
>
>
>
>
> ID         V1        V2        V3        V4
>
> 1          1          3          1
>
> 2          5          6
>
> 3          1          1          2
>
> 4          2          1
>
> 5          6          1
>
>
>
> So basically I would like to remove all the empty places and move the
> entries to the left.
>
>
>
> So does anybody have an idea on how to do this?
>
>
>
> Thanks in advance
>
>
>
> Samir
>
>
>
> GfK BH
> Centar za istrazivanje trzista i javnog mnijenja d.o.o.
>
> Samir Omerovic
> Istrazivac/Researcher
>
> 71000 Sarajevo, Skenderija 44
> BA, Bosna i Hercegovina
> Tel. +387 33 550300
> Fax. +387 33 444226
> www.gfk.ba
> www.gfk.com
>



--
Vlad Simion
Data Analyst
Tel:      +40 720130611
Reply | Threaded
Open this post in threaded view
|

Re: Data moving

Samir Omerovic
Hi Vlad,

 

Thanks, this works fine. I will have to rewrite the syntax for I have many variables but I think it
will be ok.

 

Thanks

 

Samir

 

GfK BH
Centar za istrazivanje trzista i javnog mnijenja d.o.o.

Samir Omerovic
Istrazivac/Researcher

71000 Sarajevo, Skenderija 44
BA, Bosna i Hercegovina
Tel. +387 33 550300
Fax. +387 33 444226
www.gfk.ba
www.gfk.com

  _____  

From: vlad simion [mailto:[hidden email]]
Sent: Monday, June 25, 2007 4:13 PM
To: Samir Omerović
Cc: [hidden email]
Subject: Re: Data moving

 

Hi Samir,

i'm not sure is the most elegant solution, but, try this:

new file.
data list /id 1 v1 2 v2 3 v3 4 v4 5.
begin data
11 2 3
2 34
3 345
41234
end data.

compute j=0.
exe.
vector v = v1 to v4 / tmp(4).
loop #i = 1 to 4.
if ~miss(v(#i)) j=j+1.
if ~miss(v(#i)) tmp(j)=v(#i).
end loop.
exe.

HTH,

Vlad



On 6/25/07, Samir Omerović <[hidden email]> wrote:

Hi to all,



Does anybody know if this is possible to do in SPSS:



Let's say I have the following file:



ID         V1        V2        V3        V4

1          1                      3          1

2                      5                      6

3          1          1                      2

4                                  2          1

5          6                                  1





And I would like to get this file:





ID         V1        V2        V3        V4

1          1          3          1

2          5          6

3          1          1          2

4          2          1

5          6          1



So basically I would like to remove all the empty places and move the entries to the left.



So does anybody have an idea on how to do this?



Thanks in advance



Samir



GfK BH
Centar za istrazivanje trzista i javnog mnijenja d.o.o.

Samir Omerovic
Istrazivac/Researcher

71000 Sarajevo, Skenderija 44
BA, Bosna i Hercegovina
Tel. +387 33 550300
Fax. +387 33 444226
www.gfk.ba
www.gfk.com




--
Vlad Simion
Data Analyst
Tel:      +40 720130611
Reply | Threaded
Open this post in threaded view
|

Re: Data moving

vlad simion
Hi Samir,

you could have it wrapped into a macro, something like this:

define !test (nbvar=!tokens(1))
compute j=0.
exe.
vector v = !concat(v,1) to !concat(v,!eval(!nbvar))/ tmp(!nbvar).
loop #i = 1 to !nbvar.
if ~miss(v(#i)) j=j+1.
if ~miss(v(#i)) tmp(j)=v(#i).
end loop.
exe.
!enddefine.

and the macro call:

!test nbvar=4.

hth,

Vlad.




On 6/26/07, Samir Omerović <[hidden email]> wrote:

>
>  Hi Vlad,
>
>
>
> Thanks, this works fine. I will have to rewrite the syntax for I have many
> variables but I think it will be ok.
>
>
>
> Thanks
>
>
>
> Samir
>
>
>
> *GfK BH*
> Centar za istrazivanje trzista i javnog mnijenja d.o.o.
>
> *Samir Omerovic*
> Istrazivac/Researcher
>
> 71000 Sarajevo, Skenderija 44
> BA, Bosna i Hercegovina
> Tel. +387 33 550300
> Fax. +387 33 444226
> *www.gfk.ba*
> *www.gfk.com*
>   ------------------------------
>
> *From:* vlad simion [mailto:[hidden email]]
> *Sent:* Monday, June 25, 2007 4:13 PM
> *To:* Samir Omerović
> *Cc:* [hidden email]
> *Subject:* Re: Data moving
>
>
>
> Hi Samir,
>
> i'm not sure is the most elegant solution, but, try this:
>
> new file.
> data list /id 1 v1 2 v2 3 v3 4 v4 5.
> begin data
> 11 2 3
> 2 34
> 3 345
> 41234
> end data.
>
> compute j=0.
> exe.
> vector v = v1 to v4 / tmp(4).
> loop #i = 1 to 4.
> if ~miss(v(#i)) j=j+1.
> if ~miss(v(#i)) tmp(j)=v(#i).
> end loop.
> exe.
>
> HTH,
>
> Vlad
>
>  On 6/25/07, *Samir Omerović* <[hidden email]> wrote:
>
> Hi to all,
>
>
>
> Does anybody know if this is possible to do in SPSS:
>
>
>
> Let's say I have the following file:
>
>
>
> ID         V1        V2        V3        V4
>
> 1          1                      3          1
>
> 2                      5                      6
>
> 3          1          1                      2
>
> 4                                  2          1
>
> 5          6                                  1
>
>
>
>
>
> And I would like to get this file:
>
>
>
>
>
> ID         V1        V2        V3        V4
>
> 1          1          3          1
>
> 2          5          6
>
> 3          1          1          2
>
> 4          2          1
>
> 5          6          1
>
>
>
> So basically I would like to remove all the empty places and move the
> entries to the left.
>
>
>
> So does anybody have an idea on how to do this?
>
>
>
> Thanks in advance
>
>
>
> Samir
>
>
>
> GfK BH
> Centar za istrazivanje trzista i javnog mnijenja d.o.o.
>
> Samir Omerovic
> Istrazivac/Researcher
>
> 71000 Sarajevo, Skenderija 44
> BA, Bosna i Hercegovina
> Tel. +387 33 550300
> Fax. +387 33 444226
> www.gfk.ba
> www.gfk.com
>
>
>
>
> --
> Vlad Simion
> Data Analyst
> Tel:      +40 720130611
>



--
Vlad Simion
Data Analyst
Tel:      +40 720130611