doiong date calculations within a do repeat

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

doiong date calculations within a do repeat

carols
I have 66 duration variables to calculate. When I tried this from within a do repeat, it does not recognize the x, y etc. within the date calculation computation.

Is this even possible? Or will I need to do a lot of copy and pasting changing the name of the variables?

Note do not know the macro facility if this is the answer, although it is on my list of things to do.

do repeat
               z=bopen1 bopen2 bopen3 bopen4 bopen5 bopen6 bopen7 bopen8 bopen9 bopen10
                  bopen11 bopen12 bopen13 bopen14 bopen15 bopen16 bopen17 bopen18 bopen19 bopen20
                  bopen21 bopen22 bopen23 bopen24 bopen25 bopen26 bopen27 bopen28 bopen29 bopen30
                  bopen31 bopen32 bopen33 bopen34 bopen35 bopen36 bopen37 bopen38 bopen39 bopen40
                  bopen41 bopen42 bopen43 bopen44 bopen45 bopen46 bopen47 bopen48 bopen49 bopen50
                  bopen51 bopen52 bopen53 bopen54 bopen55 bopen56 bopen57 bopen58 bopen59 bopen60
                  bopen61 bopen62 bopen63 bopen64 bopen65 bopen66/        
               a=bclose1 bclose2 bclose3 bclose4 bclose5 bclose6 bclose7 bclose8 bclose9 bclose10
                  bclose11 bclose12 bclose13 bclose14 bclose15 bclose16 bclose17 bclose18 bclose19 bclose20
                 bclose21 bclose22 bclose23 bclose24 bclose25 bclose26 bclose27 bclose28 bclose29 bclose30
                 bclose41 bclose42 bclose43 bclose44 bclose45 bclose44 bclose47 bclose48 bclose49 bclose50
                 bclose51 bclose52 bclose53 bclose54 bclose55 bclose56 bclose57 bclose58 bclose59 bclose60
                 bclose61 bclose62 bclose63 bclose64 bclose65 bclose66/w=bdur1 to bdur66.
           

COMPUTE  w=RND((a- z / time.days(1)).
VARIABLE LEVEL  w (SCALE).
FORMATS  w (F5.0).
VARIABLE WIDTH  w(5).
end repeat.
Reply | Threaded
Open this post in threaded view
|

Re: doiong date calculations within a do repeat

David Marso
Administrator

Missing parentheses?
If bopen1 -> bopen66 are contiguous, ditto for bclose then this can be more compactly coded as:

NUMERIC bdur1 to bdur66 (F5.0).
FORMATS bdur1 to bdur66 (F5.0).
FORMATS  bdur1 to bdur66  (F5.0).
VARIABLE WIDTH  bdur1 to bdur66 (5).

VECTOR b=bopen1 TO bopen66 /c=bclose1 TO bclose66/d=bdur1 TO bdur66.
LOOP #=1 TO 66.
COMPUTE d(#)=RND(  (  c(#)- b(#)     )     / time.days(1)).
END LOOP.


carols wrote
I have 66 duration variables to calculate. When I tried this from within a do repeat, it does not recognize the x, y etc. within the date calculation computation.

Is this even possible? Or will I need to do a lot of copy and pasting changing the name of the variables?

Note do not know the macro facility if this is the answer, although it is on my list of things to do.

do repeat
               z=bopen1 bopen2 bopen3 bopen4 bopen5 bopen6 bopen7 bopen8 bopen9 bopen10
                  bopen11 bopen12 bopen13 bopen14 bopen15 bopen16 bopen17 bopen18 bopen19 bopen20
                  bopen21 bopen22 bopen23 bopen24 bopen25 bopen26 bopen27 bopen28 bopen29 bopen30
                  bopen31 bopen32 bopen33 bopen34 bopen35 bopen36 bopen37 bopen38 bopen39 bopen40
                  bopen41 bopen42 bopen43 bopen44 bopen45 bopen46 bopen47 bopen48 bopen49 bopen50
                  bopen51 bopen52 bopen53 bopen54 bopen55 bopen56 bopen57 bopen58 bopen59 bopen60
                  bopen61 bopen62 bopen63 bopen64 bopen65 bopen66/        
               a=bclose1 bclose2 bclose3 bclose4 bclose5 bclose6 bclose7 bclose8 bclose9 bclose10
                  bclose11 bclose12 bclose13 bclose14 bclose15 bclose16 bclose17 bclose18 bclose19 bclose20
                 bclose21 bclose22 bclose23 bclose24 bclose25 bclose26 bclose27 bclose28 bclose29 bclose30
                 bclose41 bclose42 bclose43 bclose44 bclose45 bclose44 bclose47 bclose48 bclose49 bclose50
                 bclose51 bclose52 bclose53 bclose54 bclose55 bclose56 bclose57 bclose58 bclose59 bclose60
                 bclose61 bclose62 bclose63 bclose64 bclose65 bclose66/w=bdur1 to bdur66.
           

COMPUTE  w=RND((a- z / time.days(1)).
VARIABLE LEVEL  w (SCALE).
FORMATS  w (F5.0).
VARIABLE WIDTH  w(5).
end repeat.
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: doiong date calculations within a do repeat

David Marso
Administrator


Of course you could also use TO on the DO REPEAT pieces.

David Marso wrote
Missing parentheses?
If bopen1 -> bopen66 are contiguous, ditto for bclose then this can be more compactly coded as:

NUMERIC bdur1 to bdur66 (F5.0).
FORMATS bdur1 to bdur66 (F5.0).
FORMATS  bdur1 to bdur66  (F5.0).
VARIABLE WIDTH  bdur1 to bdur66 (5).

VECTOR b=bopen1 TO bopen66 /c=bclose1 TO bclose66/d=bdur1 TO bdur66.
LOOP #=1 TO 66.
COMPUTE d(#)=RND(  (  c(#)- b(#)     )     / time.days(1)).
END LOOP.


carols wrote
I have 66 duration variables to calculate. When I tried this from within a do repeat, it does not recognize the x, y etc. within the date calculation computation.

Is this even possible? Or will I need to do a lot of copy and pasting changing the name of the variables?

Note do not know the macro facility if this is the answer, although it is on my list of things to do.

do repeat
               z=bopen1 bopen2 bopen3 bopen4 bopen5 bopen6 bopen7 bopen8 bopen9 bopen10
                  bopen11 bopen12 bopen13 bopen14 bopen15 bopen16 bopen17 bopen18 bopen19 bopen20
                  bopen21 bopen22 bopen23 bopen24 bopen25 bopen26 bopen27 bopen28 bopen29 bopen30
                  bopen31 bopen32 bopen33 bopen34 bopen35 bopen36 bopen37 bopen38 bopen39 bopen40
                  bopen41 bopen42 bopen43 bopen44 bopen45 bopen46 bopen47 bopen48 bopen49 bopen50
                  bopen51 bopen52 bopen53 bopen54 bopen55 bopen56 bopen57 bopen58 bopen59 bopen60
                  bopen61 bopen62 bopen63 bopen64 bopen65 bopen66/        
               a=bclose1 bclose2 bclose3 bclose4 bclose5 bclose6 bclose7 bclose8 bclose9 bclose10
                  bclose11 bclose12 bclose13 bclose14 bclose15 bclose16 bclose17 bclose18 bclose19 bclose20
                 bclose21 bclose22 bclose23 bclose24 bclose25 bclose26 bclose27 bclose28 bclose29 bclose30
                 bclose41 bclose42 bclose43 bclose44 bclose45 bclose44 bclose47 bclose48 bclose49 bclose50
                 bclose51 bclose52 bclose53 bclose54 bclose55 bclose56 bclose57 bclose58 bclose59 bclose60
                 bclose61 bclose62 bclose63 bclose64 bclose65 bclose66/w=bdur1 to bdur66.
           

COMPUTE  w=RND((a- z / time.days(1)).
VARIABLE LEVEL  w (SCALE).
FORMATS  w (F5.0).
VARIABLE WIDTH  w(5).
end repeat.
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
|

FW: doiong date calculations within a do repeat

Anthony Babinec
In reply to this post by carols
Carol,
I have not stared too closely at your z, a, w lists.
Assuming that they conform and that the variables exist,
you should realize that the names z, a, w are "stand-in" names
for the lists of variables (opens, closes, durations).

The END REPEAT could be placed right after the COMPUTE.
For fun, you can use END REPEAT PRINT to see the "constructed"
compute statements.

In VARIABLE LEVEL, FORMATS, VARIABLE WIDTH you must
use actual variable names, not the stand-in name w.

Also, the new variables are derived when you run a procedure.


Tony Babinec
[hidden email]


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
carols
Sent: Thursday, January 14, 2016 5:54 PM
To: [hidden email]
Subject: doiong date calculations within a do repeat

I have 66 duration variables to calculate. When I tried this from within a
do repeat, it does not recognize the x, y etc. within the date calculation
computation.

Is this even possible? Or will I need to do a lot of copy and pasting
changing the name of the variables?

Note do not know the macro facility if this is the answer, although it is on
my list of things to do.

do repeat
               z=bopen1 bopen2 bopen3 bopen4 bopen5 bopen6 bopen7 bopen8
bopen9 bopen10
                  bopen11 bopen12 bopen13 bopen14 bopen15 bopen16 bopen17
bopen18 bopen19 bopen20
                  bopen21 bopen22 bopen23 bopen24 bopen25 bopen26 bopen27
bopen28 bopen29 bopen30
                  bopen31 bopen32 bopen33 bopen34 bopen35 bopen36 bopen37
bopen38 bopen39 bopen40
                  bopen41 bopen42 bopen43 bopen44 bopen45 bopen46 bopen47
bopen48 bopen49 bopen50
                  bopen51 bopen52 bopen53 bopen54 bopen55 bopen56 bopen57
bopen58 bopen59 bopen60
                  bopen61 bopen62 bopen63 bopen64 bopen65 bopen66/        
               a=bclose1 bclose2 bclose3 bclose4 bclose5 bclose6 bclose7
bclose8 bclose9 bclose10
                  bclose11 bclose12 bclose13 bclose14 bclose15 bclose16
bclose17 bclose18 bclose19 bclose20
                 bclose21 bclose22 bclose23 bclose24 bclose25 bclose26
bclose27 bclose28 bclose29 bclose30
                 bclose41 bclose42 bclose43 bclose44 bclose45 bclose44
bclose47 bclose48 bclose49 bclose50
                 bclose51 bclose52 bclose53 bclose54 bclose55 bclose56
bclose57 bclose58 bclose59 bclose60
                 bclose61 bclose62 bclose63 bclose64 bclose65
bclose66/w=bdur1 to bdur66.
           

COMPUTE  w=RND((a- z / time.days(1)).
VARIABLE LEVEL  w (SCALE).
FORMATS  w (F5.0).
VARIABLE WIDTH  w(5).
end repeat.



--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/doiong-date-calculations-withi
n-a-do-repeat-tp5731284.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

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

Re: FW: doiong date calculations within a do repeat

Bruce Weaver
Administrator
Tony is suggesting something like this, I think:

* If bopen and bclose variables are not contiguous, revert to
* your complete listing of them, OR use SORT VARIABLES to
* sort your variables by NAME, then use keyword TO.

DO REPEAT
  z= bopen1 TO bopen66 /
  a= bclose1 TO bclose66 /
  w= bdur1 TO bdur66.
- COMPUTE  w=RND( (a-z) / time.days(1) ). /* Right parenthesis on (a-z) was missing.
END REPEAT.
VARIABLE LEVEL bdur1 TO bdur66 (SCALE).
FORMATS bdur1 TO bdur66 (F5.0).
VARIABLE WIDTH bdur1 TO bdur66(5).
DESCRIPTIVES bdur1 TO bdur66.



Anthony Babinec wrote
Carol,
I have not stared too closely at your z, a, w lists.
Assuming that they conform and that the variables exist,
you should realize that the names z, a, w are "stand-in" names
for the lists of variables (opens, closes, durations).

The END REPEAT could be placed right after the COMPUTE.
For fun, you can use END REPEAT PRINT to see the "constructed"
compute statements.

In VARIABLE LEVEL, FORMATS, VARIABLE WIDTH you must
use actual variable names, not the stand-in name w.

Also, the new variables are derived when you run a procedure.


Tony Babinec
[hidden email]


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
carols
Sent: Thursday, January 14, 2016 5:54 PM
To: [hidden email]
Subject: doiong date calculations within a do repeat

I have 66 duration variables to calculate. When I tried this from within a
do repeat, it does not recognize the x, y etc. within the date calculation
computation.

Is this even possible? Or will I need to do a lot of copy and pasting
changing the name of the variables?

Note do not know the macro facility if this is the answer, although it is on
my list of things to do.

do repeat
               z=bopen1 bopen2 bopen3 bopen4 bopen5 bopen6 bopen7 bopen8
bopen9 bopen10
                  bopen11 bopen12 bopen13 bopen14 bopen15 bopen16 bopen17
bopen18 bopen19 bopen20
                  bopen21 bopen22 bopen23 bopen24 bopen25 bopen26 bopen27
bopen28 bopen29 bopen30
                  bopen31 bopen32 bopen33 bopen34 bopen35 bopen36 bopen37
bopen38 bopen39 bopen40
                  bopen41 bopen42 bopen43 bopen44 bopen45 bopen46 bopen47
bopen48 bopen49 bopen50
                  bopen51 bopen52 bopen53 bopen54 bopen55 bopen56 bopen57
bopen58 bopen59 bopen60
                  bopen61 bopen62 bopen63 bopen64 bopen65 bopen66/        
               a=bclose1 bclose2 bclose3 bclose4 bclose5 bclose6 bclose7
bclose8 bclose9 bclose10
                  bclose11 bclose12 bclose13 bclose14 bclose15 bclose16
bclose17 bclose18 bclose19 bclose20
                 bclose21 bclose22 bclose23 bclose24 bclose25 bclose26
bclose27 bclose28 bclose29 bclose30
                 bclose41 bclose42 bclose43 bclose44 bclose45 bclose44
bclose47 bclose48 bclose49 bclose50
                 bclose51 bclose52 bclose53 bclose54 bclose55 bclose56
bclose57 bclose58 bclose59 bclose60
                 bclose61 bclose62 bclose63 bclose64 bclose65
bclose66/w=bdur1 to bdur66.
           

COMPUTE  w=RND((a- z / time.days(1)).
VARIABLE LEVEL  w (SCALE).
FORMATS  w (F5.0).
VARIABLE WIDTH  w(5).
end repeat.



--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/doiong-date-calculations-withi
n-a-do-repeat-tp5731284.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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
--
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: FW: doiong date calculations within a do repeat

carols
I thank you all for your help - and yes a ")" was missing which I have added.

Unfortunately the variables are not continuous - which is why I mentioned macros because I know this would be a way to create the long list of variable names which are identical save for the numerical indicator.

However even with the ) added, it still won't run, telling me that w, a and b are undefined.

I think but am unsure that for whatever reason you can't do date calculations within a do repeat.

I am on a time crunch now so am going to do a lot of copy and paste to get this this to run. If anyone has a better idea of why it is not working, would be very interested.
Reply | Threaded
Open this post in threaded view
|

Re: FW: doiong date calculations within a do repeat

Bruce Weaver
Administrator
What kind of variables are the bopen and bclose variables?  Does the following work?

COMPUTE bdur1 = RND((bclose1 - bopen1) / time.days(1)).
EXECUTE.


carols wrote
I thank you all for your help - and yes a ")" was missing which I have added.

Unfortunately the variables are not continuous - which is why I mentioned macros because I know this would be a way to create the long list of variable names which are identical save for the numerical indicator.

However even with the ) added, it still won't run, telling me that w, a and b are undefined.

I think but am unsure that for whatever reason you can't do date calculations within a do repeat.

I am on a time crunch now so am going to do a lot of copy and paste to get this this to run. If anyone has a better idea of why it is not working, would be very interested.
--
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: FW: doiong date calculations within a do repeat

carols
They are date fields. And the code you wrote works. What I am doing right now is literally running through that same code 66 times, changing the variable name with each iteration.

Seems a waste of time since that is supposed to be the purpose of a do repeat. However as I said under deadline and figuring out why I can't get it to work within a do repeat (which I use all the time with no problem) will take more time than the brute force method.
Reply | Threaded
Open this post in threaded view
|

Re: doiong date calculations within a do repeat

Jon Peck
In reply to this post by Anthony Babinec
When TO does not work, because the variables are not contiguous, consider the SPSSINC SELECT VARIABLES extension command (on Utilities).  It defines a macro listing variables selected by various metadata including patterns in names, variable type, variable level, role, and custom attributes.  Then you can just use that macro in places where variable lists are expected.

If you don't already have this installed, you can add it from the Utilities menu (V22 or later) or get it from the SPSS Community website.

On Friday, January 15, 2016, Anthony Babinec <[hidden email]> wrote:
Carol,
I have not stared too closely at your z, a, w lists.
Assuming that they conform and that the variables exist,
you should realize that the names z, a, w are "stand-in" names
for the lists of variables (opens, closes, durations).

The END REPEAT could be placed right after the COMPUTE.
For fun, you can use END REPEAT PRINT to see the "constructed"
compute statements.

In VARIABLE LEVEL, FORMATS, VARIABLE WIDTH you must
use actual variable names, not the stand-in name w.

Also, the new variables are derived when you run a procedure.


Tony Babinec
<a href="javascript:;" onclick="_e(event, &#39;cvml&#39;, &#39;tbabinec@sbcglobal.net&#39;)">tbabinec@...


-----Original Message-----
From: SPSSX(r) Discussion [mailto:<a href="javascript:;" onclick="_e(event, &#39;cvml&#39;, &#39;SPSSX-L@LISTSERV.UGA.EDU&#39;)">SPSSX-L@...] On Behalf Of
carols
Sent: Thursday, January 14, 2016 5:54 PM
To: <a href="javascript:;" onclick="_e(event, &#39;cvml&#39;, &#39;SPSSX-L@LISTSERV.UGA.EDU&#39;)">SPSSX-L@...
Subject: doiong date calculations within a do repeat

I have 66 duration variables to calculate. When I tried this from within a
do repeat, it does not recognize the x, y etc. within the date calculation
computation.

Is this even possible? Or will I need to do a lot of copy and pasting
changing the name of the variables?

Note do not know the macro facility if this is the answer, although it is on
my list of things to do.

do repeat
               z=bopen1 bopen2 bopen3 bopen4 bopen5 bopen6 bopen7 bopen8
bopen9 bopen10
                  bopen11 bopen12 bopen13 bopen14 bopen15 bopen16 bopen17
bopen18 bopen19 bopen20
                  bopen21 bopen22 bopen23 bopen24 bopen25 bopen26 bopen27
bopen28 bopen29 bopen30
                  bopen31 bopen32 bopen33 bopen34 bopen35 bopen36 bopen37
bopen38 bopen39 bopen40
                  bopen41 bopen42 bopen43 bopen44 bopen45 bopen46 bopen47
bopen48 bopen49 bopen50
                  bopen51 bopen52 bopen53 bopen54 bopen55 bopen56 bopen57
bopen58 bopen59 bopen60
                  bopen61 bopen62 bopen63 bopen64 bopen65 bopen66/
               a=bclose1 bclose2 bclose3 bclose4 bclose5 bclose6 bclose7
bclose8 bclose9 bclose10
                  bclose11 bclose12 bclose13 bclose14 bclose15 bclose16
bclose17 bclose18 bclose19 bclose20
                 bclose21 bclose22 bclose23 bclose24 bclose25 bclose26
bclose27 bclose28 bclose29 bclose30
                 bclose41 bclose42 bclose43 bclose44 bclose45 bclose44
bclose47 bclose48 bclose49 bclose50
                 bclose51 bclose52 bclose53 bclose54 bclose55 bclose56
bclose57 bclose58 bclose59 bclose60
                 bclose61 bclose62 bclose63 bclose64 bclose65
bclose66/w=bdur1 to bdur66.


COMPUTE  w=RND((a- z / time.days(1)).
VARIABLE LEVEL  w (SCALE).
FORMATS  w (F5.0).
VARIABLE WIDTH  w(5).
end repeat.



--
View this message in context:
<a href="http://spssx-discussion.1045642.n5.nabble.com/doiong-date-calculations-withi n-a-do-repeat-tp5731284.html" target="_blank">http://spssx-discussion.1045642.n5.nabble.com/doiong-date-calculations-withi
n-a-do-repeat-tp5731284.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to
<a href="javascript:;" onclick="_e(event, &#39;cvml&#39;, &#39;LISTSERV@LISTSERV.UGA.EDU&#39;)">LISTSERV@... (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
<a href="javascript:;" onclick="_e(event, &#39;cvml&#39;, &#39;LISTSERV@LISTSERV.UGA.EDU&#39;)">LISTSERV@... (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


--
Jon K Peck
[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: FW: doiong date calculations within a do repeat

David Marso
Administrator
In reply to this post by carols
Date calcs work perfectly fine in DO REPEAT.
You are not disclosing something. (like exact error msgs etc).

carols wrote
I thank you all for your help - and yes a ")" was missing which I have added.

Unfortunately the variables are not continuous - which is why I mentioned macros because I know this would be a way to create the long list of variable names which are identical save for the numerical indicator.

However even with the ) added, it still won't run, telling me that w, a and b are undefined.

I think but am unsure that for whatever reason you can't do date calculations within a do repeat.

I am on a time crunch now so am going to do a lot of copy and paste to get this this to run. If anyone has a better idea of why it is not working, would be very interested.
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: doiong date calculations within a do repeat

Rich Ulrich
In reply to this post by carols
You did not show us the error message.  That could have been useful.

I suppose that it is too late now, but ... I suspect that your problem would be solved
if you established your new variable /before/  you start the DO REPEAT.

Use VECTOR  and follow it with the Formats, Width, Level, if you want.

--
Rich Ulrich

> Date: Thu, 14 Jan 2016 16:53:57 -0700
> From: [hidden email]
> Subject: doiong date calculations within a do repeat
> To: [hidden email]
>
> I have 66 duration variables to calculate. When I tried this from within a do
> repeat, it does not recognize the x, y etc. within the date calculation
> computation.

.
.
.
>
>
> COMPUTE w=RND((a- z / time.days(1)).
> VARIABLE LEVEL w (SCALE).
> FORMATS w (F5.0).
> VARIABLE WIDTH w(5).
> end repeat.
>

===================== 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: FW: doiong date calculations within a do repeat

Bruce Weaver
Administrator
In reply to this post by David Marso
Agreed.  But meanwhile, maybe a quick & dirty macro would work.  Something like this, maybe?

DEFINE !MyLoop (NumLoops = !CMDEND)
!DO !i = 1 !TO !NumLoops
!LET !dur = !CONCAT("bdur",!i)
!LET !close = !CONCAT("bclose",!i)
!LET !open = !CONCAT("bopen",!i)
COMPUTE !dur = RND((!close - !open) / time.days(1)).
!DOEND
!ENDDEFINE.

*SET MPRINT ON.
!MyLoop NumLoops = 66.
*SET MPRINT OFF.

I just tried it with NumLoops = 2 (and the SET lines uncommented), and saw this in the output window:

2069  0 M>  COMPUTE bdur1 = RND(( bclose1 - bopen1 ) / time.days(1)).
2070  0 M>  COMPUTE bdur2 = RND(( bclose2 - bopen2 ) / time.days(1)).

I also saw some error messages, because I have no data file defined; but the key thing is, it appears to be generating the COMPUTE commands properly.  ;-)

HTH.



David Marso wrote
Date calcs work perfectly fine in DO REPEAT.
You are not disclosing something. (like exact error msgs etc).

carols wrote
I thank you all for your help - and yes a ")" was missing which I have added.

Unfortunately the variables are not continuous - which is why I mentioned macros because I know this would be a way to create the long list of variable names which are identical save for the numerical indicator.

However even with the ) added, it still won't run, telling me that w, a and b are undefined.

I think but am unsure that for whatever reason you can't do date calculations within a do repeat.

I am on a time crunch now so am going to do a lot of copy and paste to get this this to run. If anyone has a better idea of why it is not working, would be very interested.
--
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: FW: doiong date calculations within a do repeat

carols
I had other calculations to do and that worked brilliantly. Many many thanks.

I have always done this sort of work in SAS so never bothered to learn the SPSS scripting facility. Since I don't have SAS at my current position, it is clear I need to learn it.

When I have a little time will experiment on whether the do repeat failed because of the format statement. That does make sense although I would never have thought about it.

Carol
Reply | Threaded
Open this post in threaded view
|

Re: FW: doiong date calculations within a do repeat

Bruce Weaver
Administrator
I assume you're referring to the macro I posted.  One advantage of the macro (over DO-REPEAT) is that it works regardless of whether the various sets of numbered variables are contiguous or not.  


carols wrote
I had other calculations to do and that worked brilliantly. Many many thanks.

I have always done this sort of work in SAS so never bothered to learn the SPSS scripting facility. Since I don't have SAS at my current position, it is clear I need to learn it.

When I have a little time will experiment on whether the do repeat failed because of the format statement. That does make sense although I would never have thought about it.

Carol
--
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/).