Fwd: Stacking data to left - restructure query

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

Fwd: Stacking data to left - restructure query

Mark Webb-5

I want to stack data to the left of a set of variables.
Below is an example of what format I have and what I want.
Any ideas ?

Have

 

 

 

 

 

 

b1

b2

b3

b4

b5

b6

b7

.

.

.

4

.

.

.

1

2

.

.

.

6

.

.

.

3

4

.

.

.

 

 

 

 

 

 

 

Want

 

 

 

 

 

 

b1x

b2x

b3x

b4x

b5x

b6x

b7x

4

.

.

.

.

.

.

1

2

6

.

.

.

.

3

4

.

.

.

.

.


--
Mark Webb

Line +27 (21) 786 4379
Cell +27 (72) 199 1000
Fax to email +27 (86) 5513075
Skype  webbmark
Email  [hidden email]
===================== 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
|

AW: Stacking data to left - restructure query

la volta statistics

Hi Mark

 

You could use the following syntax for your example:

In order do use the Do Repeat – End Repeat code for making the new vars, I have changed the names of the new vars from b1x to bx1 etc.

 

Hope this helps,

Christian

 

Do repeat R = bx1 to bx7.

Numeric R.

End repeat.

 

Vector a = b1 to b7.

Vector b = bx1 to bx7.

Compute #i = 1.

 

Loop #k = 1 to 7.

+ Do if Not Missing (a(#k)).

+  Compute b(#i) = (a(#k)).

+  Compute #i = #i + 1.

+ End if.

End Loop.

Exec.

 

 

**********************************
la volta statistics

Christian Schmidhauser, Dr.phil.II
Weinbergstrasse 108
CH-8006 Zürich
Tel: +41 (043) 233 98 01
Fax: +41 (043) 233 98 02
email:
[hidden email] 
Web: www.lavolta.ch

 


Von: SPSSX(r) Discussion [mailto:[hidden email]] Im Auftrag von Mark Webb
Gesendet: Dienstag, 21. September 2010 11:30
An: [hidden email]
Betreff: Fwd: Stacking data to left - restructure query

 


I want to stack data to the left of a set of variables.
Below is an example of what format I have and what I want.
Any ideas ?


Have

 

 

 

 

 

 

b1

b2

b3

b4

b5

b6

b7

.

.

.

4

.

.

.

1

2

.

.

.

6

.

.

.

3

4

.

.

.

 

 

 

 

 

 

 

Want

 

 

 

 

 

 

b1x

b2x

b3x

b4x

b5x

b6x

b7x

4

.

.

.

.

.

.

1

2

6

.

.

.

.

3

4

.

.

.

.

.



--
Mark Webb
 
Line +27 (21) 786 4379
Cell +27 (72) 199 1000
Fax to email +27 (86) 5513075
Skype  webbmark
Email  [hidden email]
===================== 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: AW: Stacking data to left - restructure query

Jon K Peck

Here is a programmability solution to go along with the traditional technology.

begin program.
def f(data):
  return [x for x in data if not x is None]
end program.

spssinc trans result=bx1 to bx7
/formula "f([b1,b2,b3,b4,b5,b6,b7])".

Regards,

Jon Peck
SPSS, an IBM Company
[hidden email]
312-651-3435



From: la volta statistics <[hidden email]>
To: [hidden email]
Date: 09/21/2010 04:52 AM
Subject: [SPSSX-L] AW: Stacking data to left - restructure query
Sent by: "SPSSX(r) Discussion" <[hidden email]>





Hi Mark
 
You could use the following syntax for your example:
In order do use the Do Repeat – End Repeat code for making the new vars, I have changed the names of the new vars from b1x to bx1 etc.
 
Hope this helps,
Christian
 
Do repeat R = bx1 to bx7.
Numeric R.
End repeat.
 
Vector a = b1 to b7.
Vector b = bx1 to bx7.
Compute #i = 1.
 
Loop #k = 1 to 7.
+ Do if Not Missing (a(#k)).
+  Compute b(#i) = (a(#k)).
+  Compute #i = #i + 1.
+ End if.
End Loop.
Exec.
 
 
**********************************
la volta statistics

Christian Schmidhauser, Dr.phil.II
Weinbergstrasse 108
CH-8006 Zürich
Tel: +41 (043) 233 98 01
Fax: +41 (043) 233 98 02
email:
mailto:schmidhauser@...
Web:
www.lavolta.ch
 



Von: SPSSX(r) Discussion [[hidden email]] Im Auftrag von Mark Webb
Gesendet:
Dienstag, 21. September 2010 11:30
An:
[hidden email]
Betreff:
Fwd: Stacking data to left - restructure query

 

I want to stack data to the left of a set of variables.
Below is an example of what format I have and what I want.
Any ideas ?

Have
 
 
 
 
 
 
b1
b2
b3
b4
b5
b6
b7
.
.
.
4
.
.
.
1
2
.
.
.
6
.
.
.
3
4
.
.
.
 
 
 
 
 
 
 
Want
 
 
 
 
 
 
b1x
b2x
b3x
b4x
b5x
b6x
b7x
4
.
.
.
.
.
.
1
2
6
.
.
.
.
3
4
.
.
.
.
.



--
Mark Webb
 
Line +27 (21) 786 4379
Cell +27 (72) 199 1000
Fax to email +27 (86) 5513075
Skype  webbmark
Email  tomarkwebb@...
===================== 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: AW: Stacking data to left - restructure query

David Marso
Administrator
In reply to this post by Mark Webb-5
Hello,
In a similar spirit but omitting much unnecessary code.

VECTOR BK(7).
COMPUTE #=1.
DO REPEAT B=B1 TO B7.
+  DO IF NOT MISSING(B).
+    COMPUTE BK(#)=B.
+    COMPUTE #=#+1.
+  END IF.
END REPEAT.
LIST.
HTH, David


On Tue, 21 Sep 2010 12:49:58 +0200, la volta statistics
<[hidden email]> wrote:

>Hi Mark
>
>
>
>You could use the following syntax for your example:
>
>In order do use the Do Repeat � End Repeat code for making the new vars, I
>have changed the names of the new vars from b1x to bx1 etc.
>
>
>
>Hope this helps,
>
>Christian
>
>
>
>Do repeat R = bx1 to bx7.
>
>Numeric R.
>
>End repeat.
>
>
>
>Vector a = b1 to b7.
>
>Vector b = bx1 to bx7.
>
>Compute #i = 1.
>
>
>
>Loop #k = 1 to 7.
>
>+ Do if Not Missing (a(#k)).
>
>+  Compute b(#i) = (a(#k)).
>
>+  Compute #i = #i + 1.
>
>+ End if.
>
>End Loop.
>
>Exec.
>
>
>
>
>
>**********************************
>la volta statistics
>
>Christian Schmidhauser, Dr.phil.II
>Weinbergstrasse 108
>CH-8006 Z�rich
>Tel: +41 (043) 233 98 01
>Fax: +41 (043) 233 98 02
>email:  <mailto:[hidden email]> mailto:[hidden email]
>Web: www.lavolta.ch
>
>
>
>  _____
>
>Von: SPSSX(r) Discussion [mailto:[hidden email]] Im Auftrag von
>Mark Webb
>Gesendet: Dienstag, 21. September 2010 11:30
>An: [hidden email]
>Betreff: Fwd: Stacking data to left - restructure query
>
>
>
>
>I want to stack data to the left of a set of variables.
>Below is an example of what format I have and what I want.
>Any ideas ?
>
>
>
>
>
>Have
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>b1
>
>b2
>
>b3
>
>b4
>
>b5
>
>b6
>
>b7
>
>
>.
>
>.
>
>.
>
>4
>
>.
>
>.
>
>.
>
>
>1
>
>2
>
>.
>
>.
>
>.
>
>6
>
>.
>
>
>.
>
>.
>
>3
>
>4
>
>.
>
>.
>
>.
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>Want
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>b1x
>
>b2x
>
>b3x
>
>b4x
>
>b5x
>
>b6x
>
>b7x
>
>
>4
>
>.
>
>.
>
>.
>
>.
>
>.
>
>.
>
>
>1
>
>2
>
>6
>
>.
>
>.
>
>.
>
>.
>
>
>3
>
>4
>
>.
>
>.
>
>.
>
>.
>
>.
>
>
>
>
>
>--
>Mark Webb
>
>Line +27 (21) 786 4379
>Cell +27 (72) 199 1000
>Fax to email +27 (86) 5513075
>Skype  webbmark
>Email  [hidden email]
>===================== 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
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"