URGENT::::Help required in Loop Creation

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

URGENT::::Help required in Loop Creation

Richard AK
Hi Team,
 
The below requirement is an urgent one. Please help me in finding a solution.
 
I am creating a loop to read variables. The syntax is as follows:
 
COMPUTE Termination =0.
vector BASE= BA_0 to BA_273.
LOOP #xyz =0 TO 272 by 1.
DO IF Y>= ln(#xyz)
COMPUTE Termination=#xyz.
else .
end if.
END LOOP.
execute.
 
There are in total 274 variables in my data file with BA_1 to BA_273 and a variable with the name of  Y.
 
From the above LOOP our aim to calculate a variable "Termination" if Y value is >= to the calculated value , we require the argument to stop there and through the result of LOOP where argument is true at the FIRST instance.
 
For example, if Y Value is >= in(#xyz) then it has to give me a value of #xyz in my newly computed termination variable. If the condition is applying at the multiple times it has to give me the #xyz value of the first instance.
 
Thanks in advance,
Richard.
 
 
 
 
 
 

 
Reply | Threaded
Open this post in threaded view
|

Re: URGENT::::Help required in Loop Creation

David Marso
Administrator
If you attempt to run your code it will present you with several warnings.
They will be diagnostic and probably helpful to review in conjunction with a re-reading of the documentation on VECTOR and LOOP.
---
Here is an untested (probably fixed) stab at your code.
*NOTES:  Vectors use an initial index of 1 (NOT 0).
Need to have your vector declaration correspond to what is referenced in the code (ie: Where does ln(#xyz) come from?
Use BREAK to force termination of loop prior to the full set of variables.

COMPUTE Termination =0.
VECTOR BASE= BA_1 to BA_273.
LOOP #xyz =1 TO 273.
DO IF Y>= BASE(#xyz).
COMPUTE Termination=#xyz.
BREAK.
END IF.
END LOOP.
execute.
HTH, David
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: URGENT::::Help required in Loop Creation

Art Kendall
In reply to this post by Richard AK
it appears that you are trying to find out whether the value in  Y exceeds the natural log of its index along BASE. However the value of BASE does not go into the calculation.
Also, you start the array at 0.  ln(zero) is undefined.
data list list/ myvar(f1).
begin data
0
1
2
3
4
9
end data.
compute natlog = ln(myvar).
formats natlog (f8.6).
list.

results in
>Warning # 602
>The argument for the natural log function is less than or equal to zero.  The
>result has been set to the system-missing value.
>Command line: 272  Current case: 1  Current splitfile group: 1
 
 
 
 
 
myvar   natlog
 
  0    .
  1    .000000
  2    .693147
  3   1.098612
  4   1.386294
  9   2.197225


Art Kendall
Social Research Consultants


On 5/17/2011 4:58 AM, Richard AK wrote:
COMPUTE Termination =0.
vector BASE= BA_0 to BA_273.
LOOP #xyz =0 TO 272 by 1.
DO IF Y>= ln(#xyz)
COMPUTE Termination=#xyz.
else .
end if.
END LOOP.
execute.
===================== 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
Reply | Threaded
Open this post in threaded view
|

Re: URGENT::::Help required in Loop Creation

Art Kendall
see if this is what you are looking for. This example only has 4 positions in BASE. You would need to change the loop index, the missing values, and the value labels.

data list list/ y BA_0 to BA_3 (5f1).
begin data
2 9 9 9 2
2 2 9 9 9
2 2 2 2 2
2 9 9 9 9
2 9 2 9 2
2 9 9 2 2
end data.
numeric termination (f3).
COMPUTE Termination =-1.
vector BASE= BA_0 to BA_3.
LOOP #xyz =1 TO 4 .
do if (y gt ln(base(#xyz))).
break.
end if.
END LOOP.
*put back on indexing of base.
compute termination = #xyz -1.
missing values termination (-1,4).
value labels termination
 0 'first position in BASE'
 3 'last position in BASE'
 4 'value in BASE never exceeded Y'
-1 'no new value assigned'.
list.


Art Kendall
Social Research Consultants

On 5/17/2011 10:42 AM, Art Kendall wrote:
it appears that you are trying to find out whether the value in  Y exceeds the natural log of its index along BASE. However the value of BASE does not go into the calculation.
Also, you start the array at 0.  ln(zero) is undefined.
data list list/ myvar(f1).
begin data
0
1
2
3
4
9
end data.
compute natlog = ln(myvar).
formats natlog (f8.6).
list.

results in
>Warning # 602
>The argument for the natural log function is less than or equal to zero.  The
>result has been set to the system-missing value.
>Command line: 272  Current case: 1  Current splitfile group: 1
 
 
 
 
 
myvar   natlog
 
  0    .
  1    .000000
  2    .693147
  3   1.098612
  4   1.386294
  9   2.197225


Art Kendall
Social Research Consultants


On 5/17/2011 4:58 AM, Richard AK wrote:
COMPUTE Termination =0.
vector BASE= BA_0 to BA_273.
LOOP #xyz =0 TO 272 by 1.
DO IF Y>= ln(#xyz)
COMPUTE Termination=#xyz.
else .
end if.
END LOOP.
execute.
===================== 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
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: URGENT::::Help required in Loop Creation

David Marso
Administrator
In reply to this post by Art Kendall
Why do I get the premonition that this thread is likely to devolve into an ESP driven train-wreck?  Just because the existing code evaluates the natural log does not imply anything with regard to intended functionality.  OP would do well to review the documentation on VECTOR and LOOP.
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: URGENT::::Help required in Loop Creation

Richard AK
In reply to this post by Art Kendall
Hi all,
 
My problem got resolved. Thanks all of you for the help.
 
Thanks,
Richard..

On Tue, May 17, 2011 at 8:55 PM, Art Kendall <[hidden email]> wrote:
see if this is what you are looking for. This example only has 4 positions in BASE. You would need to change the loop index, the missing values, and the value labels.

data list list/ y BA_0 to BA_3 (5f1).
begin data
2 9 9 9 2
2 2 9 9 9
2 2 2 2 2
2 9 9 9 9
2 9 2 9 2
2 9 9 2 2
end data.
numeric termination (f3).
COMPUTE Termination =-1.
vector BASE= BA_0 to BA_3.
LOOP #xyz =1 TO 4 .
do if (y gt ln(base(#xyz))).
break.
end if.
END LOOP.
*put back on indexing of base.
compute termination = #xyz -1.
missing values termination (-1,4).
value labels termination
 0 'first position in BASE'
 3 'last position in BASE'
 4 'value in BASE never exceeded Y'
-1 'no new value assigned'.
list.


Art Kendall
Social Research Consultants

On 5/17/2011 10:42 AM, Art Kendall wrote:
it appears that you are trying to find out whether the value in  Y exceeds the natural log of its index along BASE. However the value of BASE does not go into the calculation.
Also, you start the array at 0.  ln(zero) is undefined.
data list list/ myvar(f1).
begin data
0
1
2
3
4
9
end data.
compute natlog = ln(myvar).
formats natlog (f8.6).
list.

results in
>Warning # 602
>The argument for the natural log function is less than or equal to zero.  The
>result has been set to the system-missing value.
>Command line: 272  Current case: 1  Current splitfile group: 1
 
 
 
 
 
myvar   natlog
 
  0    .
  1    .000000
  2    .693147
  3   1.098612
  4   1.386294
  9   2.197225


Art Kendall
Social Research Consultants


On 5/17/2011 4:58 AM, Richard AK wrote:
COMPUTE Termination =0.
vector BASE= BA_0 to BA_273.
LOOP #xyz =0 TO 272 by 1.
DO IF Y>= ln(#xyz)
COMPUTE Termination=#xyz.
else .
end if.
END LOOP.
execute.
===================== 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