Loop or Repeat

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

Loop or Repeat

mils
Hi everyone,

I have the next syntax which I need to repeat 150 times (I’ve done the first 5). After doing some research I still don't know which approach  will be the best (Loop or repeat).

compute varproportion002=0.
compute varproportion003=0.
compute varproportion004=0.
compute varproportion005=0.
if (CASE_LBL="t1f_prod1_sum" and var001>0) varproportion001=(var001/total)*100.
if (CASE_LBL="t1f_ prod1_sum" and var002>0) varproportion002=(var002/ total)*100.
if (CASE_LBL="t1f_ prod1_sum" and var003>0) varproportion003=(var003/ total)*100.
if (CASE_LBL="t1f_ prod1_sum" and var004>0) varproportion004=(var004/ total)*100.
if (CASE_LBL="t1f_ prod1_sum" and var005>0) varproportion005=(var005/ total)*100.
exe.

Any suggestions? Let me know if you need more information.

Thanks in advance!.

Mils
mils
Reply | Threaded
Open this post in threaded view
|

Re: Loop or Repeat

David Marso
Administrator
It might be helpful if you described the layout of your data!
If VAR001 ...VAR150 are contiguous then hands down VECTOR/LOOP.
---
mils wrote
Hi everyone,

I have the next syntax which I need to repeat 150 times (I’ve done the first 5). After doing some research I still don't know which approach  will be the best (Loop or repeat).

compute varproportion002=0.
compute varproportion003=0.
compute varproportion004=0.
compute varproportion005=0.
if (CASE_LBL="t1f_prod1_sum" and var001>0) varproportion001=(var001/total)*100.
if (CASE_LBL="t1f_ prod1_sum" and var002>0) varproportion002=(var002/ total)*100.
if (CASE_LBL="t1f_ prod1_sum" and var003>0) varproportion003=(var003/ total)*100.
if (CASE_LBL="t1f_ prod1_sum" and var004>0) varproportion004=(var004/ total)*100.
if (CASE_LBL="t1f_ prod1_sum" and var005>0) varproportion005=(var005/ total)*100.
exe.

Any suggestions? Let me know if you need more information.

Thanks in advance!.

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

RE: Loop or Repeat

mils
Here is an example of the data. CASE_LBL is string, the rest in numeric.
 
 
CASE_LBL var001 var002 var003 var004 var005 var006 var007 var008 total
t1f_prod1_sum 2 1 0 0 0 1 0 0 4
t1f_prod2_sum 0 0 6 1 0 0 0 0 7
t1f_prod3_sum 0 0 0 0 0 1 5 0 6
 
and here the results I would like
 
CASE_LBL var001 var002 var003 var004 var005 var006 var007 var008
t1f_prod1_sum 50 25 0 0 0 25 0 0
t1f_prod2_sum 0 0 86 14 0 0 0 0
t1f_prod3_sum 0 0 0 0 0 17 83 0
 
 
Hope it helps.
 
Thanks,
 
Mils
 

Date: Fri, 7 Dec 2012 04:29:41 -0800
From: [hidden email]
To: [hidden email]
Subject: Re: Loop or Repeat

It might be helpful if you described the layout of your data!
If VAR001 ...VAR150 are contiguous then hands down VECTOR/LOOP.
---
mils wrote
Hi everyone,

I have the next syntax which I need to repeat 150 times (I’ve done the first 5). After doing some research I still don't know which approach  will be the best (Loop or repeat).

compute varproportion002=0.
compute varproportion003=0.
compute varproportion004=0.
compute varproportion005=0.
if (CASE_LBL="t1f_prod1_sum" and var001>0) varproportion001=(var001/total)*100.
if (CASE_LBL="t1f_ prod1_sum" and var002>0) varproportion002=(var002/ total)*100.
if (CASE_LBL="t1f_ prod1_sum" and var003>0) varproportion003=(var003/ total)*100.
if (CASE_LBL="t1f_ prod1_sum" and var004>0) varproportion004=(var004/ total)*100.
if (CASE_LBL="t1f_ prod1_sum" and var005>0) varproportion005=(var005/ total)*100.
exe.

Any suggestions? Let me know if you need more information.

Thanks in advance!.

Mils
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.



If you reply to this email, your message will be added to the discussion below:
http://spssx-discussion.1045642.n5.nabble.com/Loop-or-Repeat-tp5716755p5716756.html
To unsubscribe from Loop or Repeat, click here.
NAML
mils
Reply | Threaded
Open this post in threaded view
|

RE: Loop or Repeat

David Marso
Administrator
Well,
1. ditch the IF clause and
2. fire away at either VECTOR/LOOP or DO REPEAT.
DO REPEAT solution is simpler syntactically but VECTOR/LOOP allows
you greater control in more complicated situations and is likely more efficient.
OTOH:  Stick with what you find most comfortable and KISS!
---
NUMERIC Prop001 TO Prop008.
VECTOR v=var001 TO var008 / p=prop001 to prop008.
DO IF (total GT 0).
LOOP #=1 TO 8.
COMPUTE p(#)=v(#) /total *100.
END LOOP.
END IF.
---
*OR*.
DO IF (total GT 0).
DO REPEAT v=var001 TO var008 / p=prop001 to prop008.
COMPUTE p=v /total *100.
END REPEAT.
END IF.
---
OTOH:  
1.  Your variable names belie the fact that this came from a FLIP.
2.  Your recent issue was getting SUMS from AGGREGATE.
Suggesting the following might be another approach (just tossing out some jugular code).
OTOH I will refrain from further elaboration (I do this for a living )
except that you will want to
A. look at SPLIT FILE and
B. INCLUDE for getting this off the ground ;-).
Original unaggregated/unmultilated (flipped) data
data list free / a b c.
begin data
2.00 .00 .00
1.00 .00 .00
.00 6.00 .00
.00 1.00 .00
.00 .00 .00
1.00 .00 1.00
.00 .00 5.00
.00 .00 .00
end data.
MATRIX .
GET data / var a b c / file *.
COMPUTE X=CSUM(data).
LOOP #=1 TO NROW(data).
COMPUTE data(#,:)=data(#,:)/X*100.
END LOOP.
PRINT data.
END MATRIX.

Run MATRIX procedure:

DATA
   50.00000000     .00000000     .00000000
   25.00000000     .00000000     .00000000
     .00000000   85.71428571     .00000000
     .00000000   14.28571429     .00000000
     .00000000     .00000000     .00000000
   25.00000000     .00000000   16.66666667
     .00000000     .00000000   83.33333333
     .00000000     .00000000     .00000000

------ END MATRIX -----


mils wrote
Here is an example of the data. CASE_LBL is string, the rest in numeric.  

 
 
 
  CASE_LBL
  var001
  var002
  var003
  var004
  var005
  var006
  var007
  var008
 
  total
 
 
  t1f_prod1_sum
  2
  1
  0
  0
  0
  1
  0
  0
 
  4
 
 
  t1f_prod2_sum
  0
  0
  6
  1
  0
  0
  0
  0
 
  7
 
 
  t1f_prod3_sum
  0
  0
  0
  0
  0
  1
  5
  0
 
  6
 

 and here the results I would like

 
 
 
  CASE_LBL
  var001
  var002
  var003
  var004
  var005
  var006
  var007
  var008
 
 
  t1f_prod1_sum
  50
  25
  0
  0
  0
  25
  0
  0
 
 
  t1f_prod2_sum
  0
  0
  86
  14
  0
  0
  0
  0
 
 
  t1f_prod3_sum
  0
  0
  0
  0
  0
  17
  83
  0
 

  Hope it helps. Thanks, Mils
 Date: Fri, 7 Dec 2012 04:29:41 -0800
From: [hidden email]
To: [hidden email]
Subject: Re: Loop or Repeat



        It might be helpful if you described the layout of your data!

If VAR001 ...VAR150 are contiguous then hands down VECTOR/LOOP.

---


mils wrote
Hi everyone,


I have the next syntax which I need to repeat 150 times (I’ve done the first 5). After doing some research I still don't know which approach  will be the best (Loop or repeat).


compute varproportion002=0.

compute varproportion003=0.

compute varproportion004=0.

compute varproportion005=0.

if (CASE_LBL="t1f_prod1_sum" and var001>0) varproportion001=(var001/total)*100.

if (CASE_LBL="t1f_ prod1_sum" and var002>0) varproportion002=(var002/ total)*100.

if (CASE_LBL="t1f_ prod1_sum" and var003>0) varproportion003=(var003/ total)*100.

if (CASE_LBL="t1f_ prod1_sum" and var004>0) varproportion004=(var004/ total)*100.

if (CASE_LBL="t1f_ prod1_sum" and var005>0) varproportion005=(var005/ total)*100.

exe.


Any suggestions? Let me know if you need more information.


Thanks in advance!.


Mils




       
       
       
                                Please reply to the list and not to my personal email.

Those desiring my consulting or training services please feel free to email me.
                       
       

       

       
       
                If you reply to this email, your message will be added to the discussion below:
                http://spssx-discussion.1045642.n5.nabble.com/Loop-or-Repeat-tp5716755p5716756.html
       
       
               
                To unsubscribe from Loop or Repeat, click here.

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

RE: Loop or Repeat

Bruce Weaver
Administrator
In reply to this post by mils
When you say you have to do it 150 times, do you mean that the variables actually range from var001 to var150?  Also, it appears that there is a different value of CASE_LBL on each row, so I don't understand why you have the "IF CASE_LBL" lines in your syntax.  Don't you just want something like this (untested)?

compute total = sum(var001 to var150).
numeric varprop001 to varprop150 (f5.3).
vector v = var001 to var150 / vp = varproportion001 to varproportion150.
loop # = 1 to 150.
.  compute vp(#) = v(#)/total.
end loop.
execute. /* probably not needed when code is in context.



HTH.



mils wrote
Here is an example of the data. CASE_LBL is string, the rest in numeric.  

 
 
 
  CASE_LBL
  var001
  var002
  var003
  var004
  var005
  var006
  var007
  var008
 
  total
 
 
  t1f_prod1_sum
  2
  1
  0
  0
  0
  1
  0
  0
 
  4
 
 
  t1f_prod2_sum
  0
  0
  6
  1
  0
  0
  0
  0
 
  7
 
 
  t1f_prod3_sum
  0
  0
  0
  0
  0
  1
  5
  0
 
  6
 

 and here the results I would like

 
 
 
  CASE_LBL
  var001
  var002
  var003
  var004
  var005
  var006
  var007
  var008
 
 
  t1f_prod1_sum
  50
  25
  0
  0
  0
  25
  0
  0
 
 
  t1f_prod2_sum
  0
  0
  86
  14
  0
  0
  0
  0
 
 
  t1f_prod3_sum
  0
  0
  0
  0
  0
  17
  83
  0
 

  Hope it helps. Thanks, Mils
 Date: Fri, 7 Dec 2012 04:29:41 -0800
From: [hidden email]
To: [hidden email]
Subject: Re: Loop or Repeat



        It might be helpful if you described the layout of your data!

If VAR001 ...VAR150 are contiguous then hands down VECTOR/LOOP.

---


mils wrote
Hi everyone,


I have the next syntax which I need to repeat 150 times (I’ve done the first 5). After doing some research I still don't know which approach  will be the best (Loop or repeat).


compute varproportion002=0.

compute varproportion003=0.

compute varproportion004=0.

compute varproportion005=0.

if (CASE_LBL="t1f_prod1_sum" and var001>0) varproportion001=(var001/total)*100.

if (CASE_LBL="t1f_ prod1_sum" and var002>0) varproportion002=(var002/ total)*100.

if (CASE_LBL="t1f_ prod1_sum" and var003>0) varproportion003=(var003/ total)*100.

if (CASE_LBL="t1f_ prod1_sum" and var004>0) varproportion004=(var004/ total)*100.

if (CASE_LBL="t1f_ prod1_sum" and var005>0) varproportion005=(var005/ total)*100.

exe.


Any suggestions? Let me know if you need more information.


Thanks in advance!.


Mils




       
       
       
                                Please reply to the list and not to my personal email.

Those desiring my consulting or training services please feel free to email me.
                       
       

       

       
       
                If you reply to this email, your message will be added to the discussion below:
                http://spssx-discussion.1045642.n5.nabble.com/Loop-or-Repeat-tp5716755p5716756.html
       
       
               
                To unsubscribe from Loop or Repeat, click here.

                NAML
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: Loop or Repeat

ViAnn Beadle
In reply to this post by mils

Are you just trying to get a report or will you use this result for further computation. Seems to me that this table could have been obtained easily through SUMMARIZE.

 

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of mils
Sent: Friday, December 07, 2012 5:41 AM
To: [hidden email]
Subject: Re: Loop or Repeat

 

Here is an example of the data. CASE_LBL is string, the rest in numeric.
 
 

CASE_LBL

var001

var002

var003

var004

var005

var006

var007

var008

total

t1f_prod1_sum

2

1

0

0

0

1

0

0

4

t1f_prod2_sum

0

0

6

1

0

0

0

0

7

t1f_prod3_sum

0

0

0

0

0

1

5

0

6

 
and here the results I would like
 

CASE_LBL

var001

var002

var003

var004

var005

var006

var007

var008

t1f_prod1_sum

50

25

0

0

0

25

0

0

t1f_prod2_sum

0

0

86

14

0

0

0

0

t1f_prod3_sum

0

0

0

0

0

17

83

0

 
 
Hope it helps.
 
Thanks,
 
Mils
 


Date: Fri, 7 Dec 2012 04:29:41 -0800
From: [hidden email]
To: [hidden email]
Subject: Re: Loop or Repeat

It might be helpful if you described the layout of your data!
If VAR001 ...VAR150 are contiguous then hands down VECTOR/LOOP.
---

mils wrote

Hi everyone,

I have the next syntax which I need to repeat 150 times (I’ve done the first 5). After doing some research I still don't know which approach  will be the best (Loop or repeat).

compute varproportion002=0.
compute varproportion003=0.
compute varproportion004=0.
compute varproportion005=0.
if (CASE_LBL="t1f_prod1_sum" and var001>0) varproportion001=(var001/total)*100.
if (CASE_LBL="t1f_ prod1_sum" and var002>0) varproportion002=(var002/ total)*100.
if (CASE_LBL="t1f_ prod1_sum" and var003>0) varproportion003=(var003/ total)*100.
if (CASE_LBL="t1f_ prod1_sum" and var004>0) varproportion004=(var004/ total)*100.
if (CASE_LBL="t1f_ prod1_sum" and var005>0) varproportion005=(var005/ total)*100.
exe.

Any suggestions? Let me know if you need more information.

Thanks in advance!.

Mils

Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.

 


If you reply to this email, your message will be added to the discussion below:

http://spssx-discussion.1045642.n5.nabble.com/Loop-or-Repeat-tp5716755p5716756.html

To unsubscribe from Loop or Repeat, click here.
NAML

mils

 


View this message in context: RE: Loop or Repeat
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|

RE: Loop or Repeat

mils
In reply to this post by Bruce Weaver

Problem solved.


Thanks everyone, especially Bruce and David.


Mils


 

Date: Fri, 7 Dec 2012 06:01:28 -0800
From: [hidden email]
To: [hidden email]
Subject: RE: Loop or Repeat

When you say you have to do it 150 times, do you mean that the variables actually range from var001 to var150?  Also, it appears that there is a different value of CASE_LBL on each row, so I don't understand why you have the "IF CASE_LBL" lines in your syntax.  Don't you just want something like this (untested)?

compute total = sum(var001 to var150).
numeric varprop001 to varprop150 (f5.3).
vector v = var001 to var150 / vp = varproportion001 to varproportion150.
loop # = 1 to 150.
.  compute vp(#) = v(#)/total.
end loop.
execute. /* probably not needed when code is in context.



HTH.



mils wrote
Here is an example of the data. CASE_LBL is string, the rest in numeric.  

 
 
 
  CASE_LBL
  var001
  var002
  var003
  var004
  var005
  var006
  var007
  var008
 
  total
 
 
  t1f_prod1_sum
  2
  1
  0
  0
  0
  1
  0
  0
 
  4
 
 
  t1f_prod2_sum
  0
  0
  6
  1
  0
  0
  0
  0
 
  7
 
 
  t1f_prod3_sum
  0
  0
  0
  0
  0
  1
  5
  0
 
  6
 

 and here the results I would like

 
 
 
  CASE_LBL
  var001
  var002
  var003
  var004
  var005
  var006
  var007
  var008
 
 
  t1f_prod1_sum
  50
  25
  0
  0
  0
  25
  0
  0
 
 
  t1f_prod2_sum
  0
  0
  86
  14
  0
  0
  0
  0
 
 
  t1f_prod3_sum
  0
  0
  0
  0
  0
  17
  83
  0
 

  Hope it helps. Thanks, Mils
 Date: Fri, 7 Dec 2012 04:29:41 -0800
From: [hidden email]
To: [hidden email]
Subject: Re: Loop or Repeat



        It might be helpful if you described the layout of your data!

If VAR001 ...VAR150 are contiguous then hands down VECTOR/LOOP.

---


mils wrote
Hi everyone,


I have the next syntax which I need to repeat 150 times (I’ve done the first 5). After doing some research I still don't know which approach  will be the best (Loop or repeat).


compute varproportion002=0.

compute varproportion003=0.

compute varproportion004=0.

compute varproportion005=0.

if (CASE_LBL="t1f_prod1_sum" and var001>0) varproportion001=(var001/total)*100.

if (CASE_LBL="t1f_ prod1_sum" and var002>0) varproportion002=(var002/ total)*100.

if (CASE_LBL="t1f_ prod1_sum" and var003>0) varproportion003=(var003/ total)*100.

if (CASE_LBL="t1f_ prod1_sum" and var004>0) varproportion004=(var004/ total)*100.

if (CASE_LBL="t1f_ prod1_sum" and var005>0) varproportion005=(var005/ total)*100.

exe.


Any suggestions? Let me know if you need more information.


Thanks in advance!.


Mils




       
       
       
                                Please reply to the list and not to my personal email.

Those desiring my consulting or training services please feel free to email me.
                       
       

       

       
       
                If you reply to this email, your message will be added to the discussion below:
                http://spssx-discussion.1045642.n5.nabble.com/Loop-or-Repeat-tp5716755p5716756.html
       
       
               
                To unsubscribe from Loop or Repeat, click here.

                NAML
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.



If you reply to this email, your message will be added to the discussion below:
http://spssx-discussion.1045642.n5.nabble.com/Loop-or-Repeat-tp5716755p5716761.html
To unsubscribe from Loop or Repeat, click here.
NAML
mils