variables cases concatenate

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

variables cases concatenate

Rajeshms
Hi all,

I have variables say for example

ID  A    B     C    D     E    F    G 
1   v5   v9                   v6
2   v6                 v5                  v7
3   
4   v4 
5                         v7                 v9


and I have all peoples ID and some codes in the variables A to G are missing randomly. So In this case how to make a small file of cases where we can concatenate  the codes together,where the missing is present. I just want to make the file to be read easily instead of scrolling right due to missing cases.

ID  A    B    C   D E F G
1    v5  v9   v6
2    v6  v5   v7
3
4    v4 
5    v7  v9 

A hint or a solution for the above will be appreciated.
Thanks all.
--
Regards,

SPSS



Reply | Threaded
Open this post in threaded view
|

Fwd: variables cases concatenate

Rajeshms
Hi all,

Mr.Mark sent me the solution for the above  query, but how to incorporate this for string data. The below follows the syntax,I need this to be for string variables.., thanks all


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.

---------- Forwarded message ----------
From: Mark Webb <[hidden email]>
Date: Thu, Sep 5, 2013 at 2:01 PM
Subject: Re: variables cases concatenate
To: Rajeshms <[hidden email]>


Please ask the group how to adapt it for strings.
I've had this syntax for a while - and don't use SPSS that much any more - so I can't assist with a string version - but there will be someone out there who can do it.
Good luck.


Mark Webb

Line <a href="tel:%2B27%20%2821%29%20786%204379" value="+27217864379" target="_blank">+27 (21) 786 4379
Cell <a href="tel:%2B27%20%2872%29%20199%201000" value="+27721991000" target="_blank">+27 (72) 199 1000 [Poor reception]
Fax  <a href="tel:%2B27%20%2886%29%20260%201946" value="+27862601946" target="_blank">+27 (86) 260 1946 

Skype       tomarkwebb 
Email       [hidden email] 
On 2013/09/05 09:57 AM, Rajeshms wrote:
Hi Mark,

Its working but I have the codes which is in string format. I tried to edit the syntax for string , but I am not able to get it. 

Thanks a lot.




On Thu, Sep 5, 2013 at 12:16 PM, Mark Webb <[hidden email]> wrote:
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.


Mark Webb

Line <a href="tel:%2B27%20%2821%29%20786%204379" value="+27217864379" target="_blank">+27 (21) 786 4379
Cell <a href="tel:%2B27%20%2872%29%20199%201000" value="+27721991000" target="_blank">+27 (72) 199 1000 [Poor reception]
Fax  <a href="tel:%2B27%20%2886%29%20260%201946" value="+27862601946" target="_blank">+27 (86) 260 1946 

Skype       tomarkwebb 
Email       [hidden email] 
On 2013/09/05 08:27 AM, Rajeshms wrote:
Hi all,

I have variables say for example

ID  A    B     C    D     E    F    G 
1   v5   v9                   v6
2   v6                 v5                  v7
3   
4   v4 
5                         v7                 v9


and I have all peoples ID and some codes in the variables A to G are missing randomly. So In this case how to make a small file of cases where we can concatenate  the codes together,where the missing is present. I just want to make the file to be read easily instead of scrolling right due to missing cases.

ID  A    B    C   D E F G
1    v5  v9   v6
2    v6  v5   v7
3
4    v4 
5    v7  v9 

A hint or a solution for the above will be appreciated.
Thanks all.
--
Regards,

SPSS







--
Regards,

Rajesh M S








--
Regards,

Rajesh M S




Reply | Threaded
Open this post in threaded view
|

Fwd: variables cases concatenate

Rajeshms
Hi all,

I have variables say for example

ID  A    B     C    D     E    F    G 
1   v5   v9                   v6
2   v6                 v5                  v7
3   
4   v4 
5                         v7                 v9


and I have all peoples ID and some codes in the variables A to G are missing randomly. So In this case how to make a small file of cases where we can concatenate  the codes together,where the missing is present. I just want to make the file to be read easily instead of scrolling right due to missing cases.

ID  A    B    C   D E F G
1    v5  v9   v6
2    v6  v5   v7
3
4    v4 
5    v7  v9 

I  know to use this for a numeric variables, but how to concatenate for string variables


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.
alter type v1 v2 v3 v4(a8).
***************************.
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. 

The above code works for numeric but for string how to edit this code? 

---------- Forwarded message ----------
From: Rajeshms <[hidden email]>
Date: Thu, Sep 5, 2013 at 2:52 PM
Subject: Fwd: variables cases concatenate
To: [hidden email]


Hi all,

Mr.Mark sent me the solution for the above  query, but how to incorporate this for string data. The below follows the syntax,I need this to be for string variables.., thanks all


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.

---------- Forwarded message ----------
From: Mark Webb <[hidden email]>
Date: Thu, Sep 5, 2013 at 2:01 PM
Subject: Re: variables cases concatenate
To: Rajeshms <[hidden email]>


Please ask the group how to adapt it for strings.
I've had this syntax for a while - and don't use SPSS that much any more - so I can't assist with a string version - but there will be someone out there who can do it.
Good luck.


Mark Webb

Line <a href="tel:%2B27%20%2821%29%20786%204379" value="+27217864379" target="_blank">+27 (21) 786 4379
Cell <a href="tel:%2B27%20%2872%29%20199%201000" value="+27721991000" target="_blank">+27 (72) 199 1000 [Poor reception]
Fax  <a href="tel:%2B27%20%2886%29%20260%201946" value="+27862601946" target="_blank">+27 (86) 260 1946 

Skype       tomarkwebb 
Email       [hidden email] 
On 2013/09/05 09:57 AM, Rajeshms wrote:
Hi Mark,

Its working but I have the codes which is in string format. I tried to edit the syntax for string , but I am not able to get it. 

Thanks a lot.




On Thu, Sep 5, 2013 at 12:16 PM, Mark Webb <[hidden email]> wrote:
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.


Mark Webb

Line <a href="tel:%2B27%20%2821%29%20786%204379" value="+27217864379" target="_blank">+27 (21) 786 4379
Cell <a href="tel:%2B27%20%2872%29%20199%201000" value="+27721991000" target="_blank">+27 (72) 199 1000 [Poor reception]
Fax  <a href="tel:%2B27%20%2886%29%20260%201946" value="+27862601946" target="_blank">+27 (86) 260 1946 

Skype       tomarkwebb 
Email       [hidden email] 
On 2013/09/05 08:27 AM, Rajeshms wrote:
Hi all,

I have variables say for example

ID  A    B     C    D     E    F    G 
1   v5   v9                   v6
2   v6                 v5                  v7
3   
4   v4 
5                         v7                 v9


and I have all peoples ID and some codes in the variables A to G are missing randomly. So In this case how to make a small file of cases where we can concatenate  the codes together,where the missing is present. I just want to make the file to be read easily instead of scrolling right due to missing cases.

ID  A    B    C   D E F G
1    v5  v9   v6
2    v6  v5   v7
3
4    v4 
5    v7  v9 

A hint or a solution for the above will be appreciated.
Thanks all.
--
Regards,

SPSS







--
Regards,

Rajesh M S








--
Regards,

Rajesh M S







--
Regards,

Rajesh M S




Reply | Threaded
Open this post in threaded view
|

Re: Fwd: variables cases concatenate

Andy W
In reply to this post by Rajeshms
You just need to replace ~miss(v(#i)) with the equivalent expression for a string variable, most likely an empty string, e.g. ~v(#i) = " ".

new file.
data list /id (F1.0) v1 v2 v3 v4 (4A1).
begin data
11 2 3
2  34
3 345
41234
end data.
***************************.
compute #j=0.
vector v=v1 to v4 / tmp(4,A1).
loop #i=1 to 4.
if ~v(#i) = " " #j=#j+1.
if ~v(#i) = " " tmp(#j)=v(#i).
end loop.
exe.
Andy W
apwheele@gmail.com
http://andrewpwheeler.wordpress.com/
Reply | Threaded
Open this post in threaded view
|

Re: variables cases concatenate

Richard Ristow
In reply to this post by Rajeshms
At 02:27 AM 9/5/2013, Rajeshms wrote:

>I have variables say for example
  [TestData]
id v1 v2 v3 v4

  1 1     2
  2       3  4
  3    3  4  5
  4 1  2  3  4
  5 A  B  C  D
  6    B  C  D
  7    B     D

Number of cases read:  7    Number of cases listed:  7

>and some codes in the variables v1 to v4 are missing randomly. How
>can we concatenate the [present] codes together [at the head of the list].

You've got a workable solution. Andy's approach can also work without
a separate set of variables; see below.

The other question is, whether to. Moving values between variables
like that is only meaningful if the variables are actually all
instances of the same phenomenon or measurement. In that case,
'unrolling' your data to long form using VARSTOCASES may be
preferable, especially for analysis.

Anyway, using the test data posted above,

VECTOR v = v1 TO v4.
COMPUTE #src = 1.
COMPUTE #tgt = 1.
LOOP.
.  DO IF  v(#src) EQ ' '.
.     COMPUTE #src = #src + 1.
.  ELSE.
.     COMPUTE v(#tgt) = v(#src).
.     IF #src GT #tgt   v(#src) = ' '.
.     COMPUTE #src = #src + 1.
.     COMPUTE #tgt = #tgt + 1.
.  END IF.
END LOOP IF #src GT 4.
LIST.

List
|-----------------------------|---------------------------|
|Output Created               |07-SEP-2013 22:21:29       |
|-----------------------------|---------------------------|
  [TestData]

id v1 v2 v3 v4

  1 1  2
  2 3  4
  3 3  4  5
  4 1  2  3  4
  5 A  B  C  D
  6 B  C  D
  7 B  D

Number of cases read:  7    Number of cases listed:  7

====================================================
APPENDIX: Code, and test data (not saved separately)
====================================================
new file.
data list /id (F1.0) v1 v2 v3 v4 (4A1).
begin data
11 2 3
2  34
3 345
41234
5ABCD
6 BCD
7 B D
end data.
DATASET NAME    TestData WINDOW=FRONT.
LIST.

VECTOR v = v1 TO v4.
COMPUTE #src = 1.
COMPUTE #tgt = 1.
LOOP.
.  DO IF  v(#src) EQ ' '.
.     COMPUTE #src = #src + 1.
.  ELSE.
.     COMPUTE v(#tgt) = v(#src).
.     IF #src GT #tgt   v(#src) = ' '.
.     COMPUTE #src = #src + 1.
.     COMPUTE #tgt = #tgt + 1.
.  END IF.
END LOOP IF #src GT 4.
LIST.

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