looping with dates

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

looping with dates

Zana Dael
I am trying my hand at creating variables by looping, but I'm stuck.

I want to create 24 date fields that will allow me to do calculations by
specific year. The 24 variables will have different dates but the date will
be the same for the individual variable. For example all recrods for s1988
will be the date 1/1/1989, and all records for s1989 will have the date
1/1/1990 and so on. I could have done this with 24 different compute
commands but I wanted to see if I can create looping syntax. And I couldn't.

Here is the syntax I created (which of course only gives me 1/1/1989 for
everyone of the 24 variables).


LOOP #i = 1 to 24.
DO REPEAT syear = s1988 to s2012.
COMPUTE syear = DATE.MDY(01,01,1989).
end REPEAT.
end LOOP.
execute.

But this gives me error (compute - the expression ends unexpectedly).

LOOP #i = 1 to 24.
DO REPEAT syear = s1988 to s2011.
COMPUTE syear = DATE.MDY(01,01,1989)TO DATE.MDY(01,01,2012).
end REPEAT.
end LOOP.
execute.

I would appreciate the help in fixing my syntax.

Zana

=====================
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: looping with dates

Maguin, Eugene
Try this. I'm not sure it will work because I don't that spss will do arithmetic within that function.

There's also a simpler way to do this. What you have is too complicated.

Vector syear=s1988 to s2012.
LOOP #i = 1 to 24.
COMPUTE syear)#i) = DATE.MDY(01,01,1988+#i).
end LOOP.
execute.

The question is whether spss will do arithmetic on the 1988+#i. If it won't, try this.

Vector syear=s1988 to s2012.
LOOP #i = 1 to 24.
Compute #yr=1988+#i.
COMPUTE syear)#i) = DATE.MDY(01,01,#yr).
end LOOP.
execute.

Gene Maguin


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Zana Dael
Sent: Friday, May 16, 2014 10:35 AM
To: [hidden email]
Subject: looping with dates

I am trying my hand at creating variables by looping, but I'm stuck.

I want to create 24 date fields that will allow me to do calculations by specific year. The 24 variables will have different dates but the date will be the same for the individual variable. For example all recrods for s1988 will be the date 1/1/1989, and all records for s1989 will have the date
1/1/1990 and so on. I could have done this with 24 different compute commands but I wanted to see if I can create looping syntax. And I couldn't.

Here is the syntax I created (which of course only gives me 1/1/1989 for everyone of the 24 variables).


LOOP #i = 1 to 24.
DO REPEAT syear = s1988 to s2012.
COMPUTE syear = DATE.MDY(01,01,1989).
end REPEAT.
end LOOP.
execute.

But this gives me error (compute - the expression ends unexpectedly).

LOOP #i = 1 to 24.
DO REPEAT syear = s1988 to s2011.
COMPUTE syear = DATE.MDY(01,01,1989)TO DATE.MDY(01,01,2012).
end REPEAT.
end LOOP.
execute.

I would appreciate the help in fixing my syntax.

Zana

=====================
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: looping with dates

David Marso
Administrator
In reply to this post by Zana Dael
Read up on VECTOR command!
DATA LIST /tmp 1.
BEGIN DATA
1
END DATA.

NUMERIC s1988 TO s2012 (ADATE).
VECTOR s=s1988 TO s2012.
LOOP #=1 TO 25.
COMPUTE s(#)=DATE.MDY(1,1,#+1988).
END LOOP.
EXECUTE.

Zana Dael wrote
I am trying my hand at creating variables by looping, but I'm stuck.

I want to create 24 date fields that will allow me to do calculations by
specific year. The 24 variables will have different dates but the date will
be the same for the individual variable. For example all recrods for s1988
will be the date 1/1/1989, and all records for s1989 will have the date
1/1/1990 and so on. I could have done this with 24 different compute
commands but I wanted to see if I can create looping syntax. And I couldn't.

Here is the syntax I created (which of course only gives me 1/1/1989 for
everyone of the 24 variables).


LOOP #i = 1 to 24.
DO REPEAT syear = s1988 to s2012.
COMPUTE syear = DATE.MDY(01,01,1989).
end REPEAT.
end LOOP.
execute.

But this gives me error (compute - the expression ends unexpectedly).

LOOP #i = 1 to 24.
DO REPEAT syear = s1988 to s2011.
COMPUTE syear = DATE.MDY(01,01,1989)TO DATE.MDY(01,01,2012).
end REPEAT.
end LOOP.
execute.

I would appreciate the help in fixing my syntax.

Zana

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

Re: looping with dates

David Marso
Administrator
In reply to this post by Maguin, Eugene
" I don't that spss will do arithmetic within that function."

Sure it will.  The only restriction AFAIK is that the arguments in data aggregation functions evaluate to an INTEGER.

For example COMPUTE booboo=DATE.MDY(1,1,1988.5).
will politely inform you that:

>One of the arguments to the DATE function is out of range or is not an
>integer.  The result has been set to the system-missing value.

Interesting.  Did you know that this is valid?
NUMERIC booboo (ADATE).
COMPUTE booboo=DATE.MDY(13,1,1988).
EXECUTE.
It will return 01/01/1989

Interesting that
COMPUTE booboo=DATE.MDY(2+1,1,1988) - 86400 .
returns 02/29/1988 ie 1988 was a leap year.
Neat trick for finding the last day of any particular month (subtract 1 day from the first day of the following month)

Your code assumes that s1988 TO s2012 already exist.
Also a typo in syear)#).
Note OP counted 24 variables but 1988-2012 add up to 25.
See my post in this thread.

Maguin, Eugene wrote
Try this. I'm not sure it will work because I don't that spss will do arithmetic within that function.

There's also a simpler way to do this. What you have is too complicated.

Vector syear=s1988 to s2012.
LOOP #i = 1 to 24.
COMPUTE syear)#i) = DATE.MDY(01,01,1988+#i).
end LOOP.
execute.

The question is whether spss will do arithmetic on the 1988+#i. If it won't, try this.

Vector syear=s1988 to s2012.
LOOP #i = 1 to 24.
Compute #yr=1988+#i.
COMPUTE syear)#i) = DATE.MDY(01,01,#yr).
end LOOP.
execute.

Gene Maguin


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Zana Dael
Sent: Friday, May 16, 2014 10:35 AM
To: [hidden email]
Subject: looping with dates

I am trying my hand at creating variables by looping, but I'm stuck.

I want to create 24 date fields that will allow me to do calculations by specific year. The 24 variables will have different dates but the date will be the same for the individual variable. For example all recrods for s1988 will be the date 1/1/1989, and all records for s1989 will have the date
1/1/1990 and so on. I could have done this with 24 different compute commands but I wanted to see if I can create looping syntax. And I couldn't.

Here is the syntax I created (which of course only gives me 1/1/1989 for everyone of the 24 variables).


LOOP #i = 1 to 24.
DO REPEAT syear = s1988 to s2012.
COMPUTE syear = DATE.MDY(01,01,1989).
end REPEAT.
end LOOP.
execute.

But this gives me error (compute - the expression ends unexpectedly).

LOOP #i = 1 to 24.
DO REPEAT syear = s1988 to s2011.
COMPUTE syear = DATE.MDY(01,01,1989)TO DATE.MDY(01,01,2012).
end REPEAT.
end LOOP.
execute.

I would appreciate the help in fixing my syntax.

Zana

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

Re: looping with dates

Maguin, Eugene
Yes, there is a typo. Thanks. No, I never would have guessed that those examples would work.
The fun thing about this list is discovering how limited my conceptualization of the transformation commands actually is.

Gene Maguin


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of David Marso
Sent: Friday, May 16, 2014 11:50 AM
To: [hidden email]
Subject: Re: looping with dates

" I don't that spss will do arithmetic within that function."

Sure it will.  The only restriction AFAIK is that the arguments in data aggregation functions evaluate to an INTEGER.

For example COMPUTE booboo=DATE.MDY(1,1,1988.5).
will politely inform you that:

>One of the arguments to the DATE function is out of range or is not an
>integer.  The result has been set to the system-missing value.

Interesting.  Did you know that this is valid?
NUMERIC booboo (ADATE).
COMPUTE booboo=DATE.MDY(13,1,1988).
EXECUTE.
It will return 01/01/1989

Interesting that
COMPUTE booboo=DATE.MDY(2+1,1,1988) - 86400 .
returns 02/29/1988 ie 1988 was a leap year.
Neat trick for finding the last day of any particular month (subtract 1 day from the first day of the following month)

Your code assumes that s1988 TO s2012 already exist.
Also a typo in syear)#).
Note OP counted 24 variables but 1988-2012 add up to 25.
See my post in this thread.


Maguin, Eugene wrote

> Try this. I'm not sure it will work because I don't that spss will do
> arithmetic within that function.
>
> There's also a simpler way to do this. What you have is too complicated.
>
> Vector syear=s1988 to s2012.
> LOOP #i = 1 to 24.
> COMPUTE syear)#i) = DATE.MDY(01,01,1988+#i).
> end LOOP.
> execute.
>
> The question is whether spss will do arithmetic on the 1988+#i. If it
> won't, try this.
>
> Vector syear=s1988 to s2012.
> LOOP #i = 1 to 24.
> Compute #yr=1988+#i.
> COMPUTE syear)#i) = DATE.MDY(01,01,#yr).
> end LOOP.
> execute.
>
> Gene Maguin
>
>
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:

> SPSSX-L@.UGA

> ] On Behalf Of Zana Dael
> Sent: Friday, May 16, 2014 10:35 AM
> To:

> SPSSX-L@.UGA

> Subject: looping with dates
>
> I am trying my hand at creating variables by looping, but I'm stuck.
>
> I want to create 24 date fields that will allow me to do calculations
> by specific year. The 24 variables will have different dates but the
> date will be the same for the individual variable. For example all
> recrods for
> s1988 will be the date 1/1/1989, and all records for s1989 will have
> the date
> 1/1/1990 and so on. I could have done this with 24 different compute
> commands but I wanted to see if I can create looping syntax. And I
> couldn't.
>
> Here is the syntax I created (which of course only gives me 1/1/1989
> for everyone of the 24 variables).
>
>
> LOOP #i = 1 to 24.
> DO REPEAT syear = s1988 to s2012.
> COMPUTE syear = DATE.MDY(01,01,1989).
> end REPEAT.
> end LOOP.
> execute.
>
> But this gives me error (compute - the expression ends unexpectedly).
>
> LOOP #i = 1 to 24.
> DO REPEAT syear = s1988 to s2011.
> COMPUTE syear = DATE.MDY(01,01,1989)TO DATE.MDY(01,01,2012).
> end REPEAT.
> end LOOP.
> execute.
>
> I would appreciate the help in fixing my syntax.
>
> Zana
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

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

> LISTSERV@.UGA

>  (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?"
--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/looping-with-dates-tp5726106p5726110.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: looping with dates

bdates
Amen, Gene.  I'm constantly humbled. As much as I've used matrix, I'm woefully behind in the vector command with the standard database format.  I'm going to school on all of this. Thanks.

B
________________________________________
From: SPSSX(r) Discussion [[hidden email]] on behalf of Maguin, Eugene [[hidden email]]
Sent: Friday, May 16, 2014 11:59 AM
To: [hidden email]
Subject: Re: looping with dates

Yes, there is a typo. Thanks. No, I never would have guessed that those examples would work.
The fun thing about this list is discovering how limited my conceptualization of the transformation commands actually is.

Gene Maguin


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of David Marso
Sent: Friday, May 16, 2014 11:50 AM
To: [hidden email]
Subject: Re: looping with dates

" I don't that spss will do arithmetic within that function."

Sure it will.  The only restriction AFAIK is that the arguments in data aggregation functions evaluate to an INTEGER.

For example COMPUTE booboo=DATE.MDY(1,1,1988.5).
will politely inform you that:

>One of the arguments to the DATE function is out of range or is not an
>integer.  The result has been set to the system-missing value.

Interesting.  Did you know that this is valid?
NUMERIC booboo (ADATE).
COMPUTE booboo=DATE.MDY(13,1,1988).
EXECUTE.
It will return 01/01/1989

Interesting that
COMPUTE booboo=DATE.MDY(2+1,1,1988) - 86400 .
returns 02/29/1988 ie 1988 was a leap year.
Neat trick for finding the last day of any particular month (subtract 1 day from the first day of the following month)

Your code assumes that s1988 TO s2012 already exist.
Also a typo in syear)#).
Note OP counted 24 variables but 1988-2012 add up to 25.
See my post in this thread.


Maguin, Eugene wrote

> Try this. I'm not sure it will work because I don't that spss will do
> arithmetic within that function.
>
> There's also a simpler way to do this. What you have is too complicated.
>
> Vector syear=s1988 to s2012.
> LOOP #i = 1 to 24.
> COMPUTE syear)#i) = DATE.MDY(01,01,1988+#i).
> end LOOP.
> execute.
>
> The question is whether spss will do arithmetic on the 1988+#i. If it
> won't, try this.
>
> Vector syear=s1988 to s2012.
> LOOP #i = 1 to 24.
> Compute #yr=1988+#i.
> COMPUTE syear)#i) = DATE.MDY(01,01,#yr).
> end LOOP.
> execute.
>
> Gene Maguin
>
>
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:

> SPSSX-L@.UGA

> ] On Behalf Of Zana Dael
> Sent: Friday, May 16, 2014 10:35 AM
> To:

> SPSSX-L@.UGA

> Subject: looping with dates
>
> I am trying my hand at creating variables by looping, but I'm stuck.
>
> I want to create 24 date fields that will allow me to do calculations
> by specific year. The 24 variables will have different dates but the
> date will be the same for the individual variable. For example all
> recrods for
> s1988 will be the date 1/1/1989, and all records for s1989 will have
> the date
> 1/1/1990 and so on. I could have done this with 24 different compute
> commands but I wanted to see if I can create looping syntax. And I
> couldn't.
>
> Here is the syntax I created (which of course only gives me 1/1/1989
> for everyone of the 24 variables).
>
>
> LOOP #i = 1 to 24.
> DO REPEAT syear = s1988 to s2012.
> COMPUTE syear = DATE.MDY(01,01,1989).
> end REPEAT.
> end LOOP.
> execute.
>
> But this gives me error (compute - the expression ends unexpectedly).
>
> LOOP #i = 1 to 24.
> DO REPEAT syear = s1988 to s2011.
> COMPUTE syear = DATE.MDY(01,01,1989)TO DATE.MDY(01,01,2012).
> end REPEAT.
> end LOOP.
> execute.
>
> I would appreciate the help in fixing my syntax.
>
> Zana
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

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

> LISTSERV@.UGA

>  (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?"
--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/looping-with-dates-tp5726106p5726110.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

=====================
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: looping with dates

David Marso
Administrator
Problem is they don't really teach this stuff in school.
Not really much to VECTOR
VECTOR new(dim,format).
or
VECTOR old=oldvar01 TO oldvar99.
then loop through the beast.

Really hard even to glean it from intense RTFMing.
Who would figure month can be 13 and it will wrap to Jan?
while 14 gives a range error (why not let 14 -> Feb?).
One delightful thing about MATRIX is the really crazy stuff you can throw at it.
It is also remarkably fast.
For example the following generates a 1000 x 3 matrix of uniform , multiplies it by 10 and truncates.
Then it takes the sum of squared pairwise differences of the rows and puts them into a matrix Z and Z2 using 2 alternative methods.
MATRIX.
COMPUTE X=TRUNC(UNIFORM(1000,3)*10).
COMPUTE Z={CSUM((X(:,1)-X(:,2))&**2),CSUM((X(:,1)-X(:,3))&**2),CSUM((X(:,2)-X(:,3))&**2)}.      
COMPUTE Z2=T(DIAG(SSCP({X(:,1)-X(:,2),X(:,1)-X(:,3),X(:,2)-X(:,3)}))).
PRINT Z.
PRINT Z2.
END MATRIX.




bdates wrote
Amen, Gene.  I'm constantly humbled. As much as I've used matrix, I'm woefully behind in the vector command with the standard database format.  I'm going to school on all of this. Thanks.

B
________________________________________
From: SPSSX(r) Discussion [[hidden email]] on behalf of Maguin, Eugene [[hidden email]]
Sent: Friday, May 16, 2014 11:59 AM
To: [hidden email]
Subject: Re: looping with dates

Yes, there is a typo. Thanks. No, I never would have guessed that those examples would work.
The fun thing about this list is discovering how limited my conceptualization of the transformation commands actually is.

Gene Maguin


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of David Marso
Sent: Friday, May 16, 2014 11:50 AM
To: [hidden email]
Subject: Re: looping with dates

" I don't that spss will do arithmetic within that function."

Sure it will.  The only restriction AFAIK is that the arguments in data aggregation functions evaluate to an INTEGER.

For example COMPUTE booboo=DATE.MDY(1,1,1988.5).
will politely inform you that:

>One of the arguments to the DATE function is out of range or is not an
>integer.  The result has been set to the system-missing value.

Interesting.  Did you know that this is valid?
NUMERIC booboo (ADATE).
COMPUTE booboo=DATE.MDY(13,1,1988).
EXECUTE.
It will return 01/01/1989

Interesting that
COMPUTE booboo=DATE.MDY(2+1,1,1988) - 86400 .
returns 02/29/1988 ie 1988 was a leap year.
Neat trick for finding the last day of any particular month (subtract 1 day from the first day of the following month)

Your code assumes that s1988 TO s2012 already exist.
Also a typo in syear)#).
Note OP counted 24 variables but 1988-2012 add up to 25.
See my post in this thread.


Maguin, Eugene wrote
> Try this. I'm not sure it will work because I don't that spss will do
> arithmetic within that function.
>
> There's also a simpler way to do this. What you have is too complicated.
>
> Vector syear=s1988 to s2012.
> LOOP #i = 1 to 24.
> COMPUTE syear)#i) = DATE.MDY(01,01,1988+#i).
> end LOOP.
> execute.
>
> The question is whether spss will do arithmetic on the 1988+#i. If it
> won't, try this.
>
> Vector syear=s1988 to s2012.
> LOOP #i = 1 to 24.
> Compute #yr=1988+#i.
> COMPUTE syear)#i) = DATE.MDY(01,01,#yr).
> end LOOP.
> execute.
>
> Gene Maguin
>
>
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:

> SPSSX-L@.UGA

> ] On Behalf Of Zana Dael
> Sent: Friday, May 16, 2014 10:35 AM
> To:

> SPSSX-L@.UGA

> Subject: looping with dates
>
> I am trying my hand at creating variables by looping, but I'm stuck.
>
> I want to create 24 date fields that will allow me to do calculations
> by specific year. The 24 variables will have different dates but the
> date will be the same for the individual variable. For example all
> recrods for
> s1988 will be the date 1/1/1989, and all records for s1989 will have
> the date
> 1/1/1990 and so on. I could have done this with 24 different compute
> commands but I wanted to see if I can create looping syntax. And I
> couldn't.
>
> Here is the syntax I created (which of course only gives me 1/1/1989
> for everyone of the 24 variables).
>
>
> LOOP #i = 1 to 24.
> DO REPEAT syear = s1988 to s2012.
> COMPUTE syear = DATE.MDY(01,01,1989).
> end REPEAT.
> end LOOP.
> execute.
>
> But this gives me error (compute - the expression ends unexpectedly).
>
> LOOP #i = 1 to 24.
> DO REPEAT syear = s1988 to s2011.
> COMPUTE syear = DATE.MDY(01,01,1989)TO DATE.MDY(01,01,2012).
> end REPEAT.
> end LOOP.
> execute.
>
> I would appreciate the help in fixing my syntax.
>
> Zana
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

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

> LISTSERV@.UGA

>  (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?"
--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/looping-with-dates-tp5726106p5726110.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

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

Re: looping with dates

Jon K Peck
The date functions and formats all document the valid ranges.  month 13 is allowed and treated as wrapping.  Note also this usage:
yrmoda:
The month can range from 1 through 13. Month 13 with day 0 yields the last day of the year. For
example, YRMODA(1990,13,0) produces the day number for December 31, 1990. Month 13 with any
other day yields the day of the first month of the coming year--for example, YRMODA(1990,13,1)
produces the day number for January 1, 1991.
v The day can range from 0 through 31. Day 0 is the last day of the previous month regardless of
whether it is 28, 29, 30, or 31. For example, YRMODA(1990,3,0) yields 148791.00, the day number for
February 28, 1990.


Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
phone: 720-342-5621




From:        David Marso <[hidden email]>
To:        [hidden email],
Date:        05/16/2014 12:57 PM
Subject:        Re: [SPSSX-L] looping with dates
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Problem is they don't really teach this stuff in school.
Not really much to VECTOR
VECTOR new(dim,format).
or
VECTOR old=oldvar01 TO oldvar99.
then loop through the beast.

Really hard even to glean it from intense RTFMing.
Who would figure month can be 13 and it will wrap to Jan?
while 14 gives a range error (why not let 14 -> Feb?).
One delightful thing about MATRIX is the really crazy stuff you can throw at
it.
It is also remarkably fast.
For example the following generates a 1000 x 3 matrix of uniform ,
multiplies it by 10 and truncates.
Then it takes the sum of squared pairwise differences of the rows and puts
them into a matrix Z and Z2 using 2 alternative methods.
MATRIX.
COMPUTE X=TRUNC(UNIFORM(1000,3)*10).
COMPUTE
Z={CSUM((X(:,1)-X(:,2))&**2),CSUM((X(:,1)-X(:,3))&**2),CSUM((X(:,2)-X(:,3))&**2)}.
COMPUTE Z2=T(DIAG(SSCP({X(:,1)-X(:,2),X(:,1)-X(:,3),X(:,2)-X(:,3)}))).
PRINT Z.
PRINT Z2.
END MATRIX.





bdates wrote
> Amen, Gene.  I'm constantly humbled. As much as I've used matrix, I'm
> woefully behind in the vector command with the standard database format.
> I'm going to school on all of this. Thanks.
>
> B
> ________________________________________
> From: SPSSX(r) Discussion [

> SPSSX-L@.UGA

> ] on behalf of Maguin, Eugene [

> emaguin@

> ]
> Sent: Friday, May 16, 2014 11:59 AM
> To:

> SPSSX-L@.UGA

> Subject: Re: looping with dates
>
> Yes, there is a typo. Thanks. No, I never would have guessed that those
> examples would work.
> The fun thing about this list is discovering how limited my
> conceptualization of the transformation commands actually is.
>
> Gene Maguin
>
>
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:

> SPSSX-L@.UGA

> ] On Behalf Of David Marso
> Sent: Friday, May 16, 2014 11:50 AM
> To:

> SPSSX-L@.UGA

> Subject: Re: looping with dates
>
> " I don't that spss will do arithmetic within that function."
>
> Sure it will.  The only restriction AFAIK is that the arguments in data
> aggregation functions evaluate to an INTEGER.
>
> For example COMPUTE booboo=DATE.MDY(1,1,1988.5).
> will politely inform you that:
>
>>One of the arguments to the DATE function is out of range or is not an
>>integer.  The result has been set to the system-missing value.
>
> Interesting.  Did you know that this is valid?
> NUMERIC booboo (ADATE).
> COMPUTE booboo=DATE.MDY(13,1,1988).
> EXECUTE.
> It will return 01/01/1989
>
> Interesting that
> COMPUTE booboo=DATE.MDY(2+1,1,1988) - 86400 .
> returns 02/29/1988 ie 1988 was a leap year.
> Neat trick for finding the last day of any particular month (subtract 1
> day from the first day of the following month)
>
> Your code assumes that s1988 TO s2012 already exist.
> Also a typo in syear)#).
> Note OP counted 24 variables but 1988-2012 add up to 25.
> See my post in this thread.
>
>
> Maguin, Eugene wrote
>> Try this. I'm not sure it will work because I don't that spss will do
>> arithmetic within that function.
>>
>> There's also a simpler way to do this. What you have is too complicated.
>>
>> Vector syear=s1988 to s2012.
>> LOOP #i = 1 to 24.
>> COMPUTE syear)#i) = DATE.MDY(01,01,1988+#i).
>> end LOOP.
>> execute.
>>
>> The question is whether spss will do arithmetic on the 1988+#i. If it
>> won't, try this.
>>
>> Vector syear=s1988 to s2012.
>> LOOP #i = 1 to 24.
>> Compute #yr=1988+#i.
>> COMPUTE syear)#i) = DATE.MDY(01,01,#yr).
>> end LOOP.
>> execute.
>>
>> Gene Maguin
>>
>>
>> -----Original Message-----
>> From: SPSSX(r) Discussion [mailto:
>
>> SPSSX-L@.UGA
>
>> ] On Behalf Of Zana Dael
>> Sent: Friday, May 16, 2014 10:35 AM
>> To:
>
>> SPSSX-L@.UGA
>
>> Subject: looping with dates
>>
>> I am trying my hand at creating variables by looping, but I'm stuck.
>>
>> I want to create 24 date fields that will allow me to do calculations
>> by specific year. The 24 variables will have different dates but the
>> date will be the same for the individual variable. For example all
>> recrods for
>> s1988 will be the date 1/1/1989, and all records for s1989 will have
>> the date
>> 1/1/1990 and so on. I could have done this with 24 different compute
>> commands but I wanted to see if I can create looping syntax. And I
>> couldn't.
>>
>> Here is the syntax I created (which of course only gives me 1/1/1989
>> for everyone of the 24 variables).
>>
>>
>> LOOP #i = 1 to 24.
>> DO REPEAT syear = s1988 to s2012.
>> COMPUTE syear = DATE.MDY(01,01,1989).
>> end REPEAT.
>> end LOOP.
>> execute.
>>
>> But this gives me error (compute - the expression ends unexpectedly).
>>
>> LOOP #i = 1 to 24.
>> DO REPEAT syear = s1988 to s2011.
>> COMPUTE syear = DATE.MDY(01,01,1989)TO DATE.MDY(01,01,2012).
>> end REPEAT.
>> end LOOP.
>> execute.
>>
>> I would appreciate the help in fixing my syntax.
>>
>> Zana
>>
>> =====================
>> To manage your subscription to SPSSX-L, send a message to
>
>> LISTSERV@.UGA
>
>>  (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
>
>> LISTSERV@.UGA
>
>>  (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?"
> --
> View this message in context:
>
http://spssx-discussion.1045642.n5.nabble.com/looping-with-dates-tp5726106p5726110.html
> Sent from the SPSSX Discussion mailing list archive at Nabble.com.
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

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

> LISTSERV@.UGA

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

> LISTSERV@.UGA

>  (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?"
--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/looping-with-dates-tp5726106p5726114.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


Reply | Threaded
Open this post in threaded view
|

Re: looping with dates

Rick Oliver-3
In reply to this post by David Marso
Hmmm....I thought the documentation said something about 13 for month in date functions being interpreted as January of the following year, but it doesn't.

On a related noted, day values in date functions can be 0-31. If the month has fewer than 31 days, then the date rolls over to the next month. That is documented. If it's 0, it's interpreted as the last day of the previous month. That was not previously documented but will be in the next release.



Rick Oliver
Senior Information Developer
IBM Business Analytics (SPSS)
E-mail: [hidden email]




From:        David Marso <[hidden email]>
To:        [hidden email],
Date:        05/16/2014 02:00 PM
Subject:        Re: looping with dates
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Problem is they don't really teach this stuff in school.
Not really much to VECTOR
VECTOR new(dim,format).
or
VECTOR old=oldvar01 TO oldvar99.
then loop through the beast.

Really hard even to glean it from intense RTFMing.
Who would figure month can be 13 and it will wrap to Jan?
while 14 gives a range error (why not let 14 -> Feb?).
One delightful thing about MATRIX is the really crazy stuff you can throw at
it.
It is also remarkably fast.
For example the following generates a 1000 x 3 matrix of uniform ,
multiplies it by 10 and truncates.
Then it takes the sum of squared pairwise differences of the rows and puts
them into a matrix Z and Z2 using 2 alternative methods.
MATRIX.
COMPUTE X=TRUNC(UNIFORM(1000,3)*10).
COMPUTE
Z={CSUM((X(:,1)-X(:,2))&**2),CSUM((X(:,1)-X(:,3))&**2),CSUM((X(:,2)-X(:,3))&**2)}.
COMPUTE Z2=T(DIAG(SSCP({X(:,1)-X(:,2),X(:,1)-X(:,3),X(:,2)-X(:,3)}))).
PRINT Z.
PRINT Z2.
END MATRIX.





bdates wrote
> Amen, Gene.  I'm constantly humbled. As much as I've used matrix, I'm
> woefully behind in the vector command with the standard database format.
> I'm going to school on all of this. Thanks.
>
> B
> ________________________________________
> From: SPSSX(r) Discussion [

> SPSSX-L@.UGA

> ] on behalf of Maguin, Eugene [

> emaguin@

> ]
> Sent: Friday, May 16, 2014 11:59 AM
> To:

> SPSSX-L@.UGA

> Subject: Re: looping with dates
>
> Yes, there is a typo. Thanks. No, I never would have guessed that those
> examples would work.
> The fun thing about this list is discovering how limited my
> conceptualization of the transformation commands actually is.
>
> Gene Maguin
>
>
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:

> SPSSX-L@.UGA

> ] On Behalf Of David Marso
> Sent: Friday, May 16, 2014 11:50 AM
> To:

> SPSSX-L@.UGA

> Subject: Re: looping with dates
>
> " I don't that spss will do arithmetic within that function."
>
> Sure it will.  The only restriction AFAIK is that the arguments in data
> aggregation functions evaluate to an INTEGER.
>
> For example COMPUTE booboo=DATE.MDY(1,1,1988.5).
> will politely inform you that:
>
>>One of the arguments to the DATE function is out of range or is not an
>>integer.  The result has been set to the system-missing value.
>
> Interesting.  Did you know that this is valid?
> NUMERIC booboo (ADATE).
> COMPUTE booboo=DATE.MDY(13,1,1988).
> EXECUTE.
> It will return 01/01/1989
>
> Interesting that
> COMPUTE booboo=DATE.MDY(2+1,1,1988) - 86400 .
> returns 02/29/1988 ie 1988 was a leap year.
> Neat trick for finding the last day of any particular month (subtract 1
> day from the first day of the following month)
>
> Your code assumes that s1988 TO s2012 already exist.
> Also a typo in syear)#).
> Note OP counted 24 variables but 1988-2012 add up to 25.
> See my post in this thread.
>
>
> Maguin, Eugene wrote
>> Try this. I'm not sure it will work because I don't that spss will do
>> arithmetic within that function.
>>
>> There's also a simpler way to do this. What you have is too complicated.
>>
>> Vector syear=s1988 to s2012.
>> LOOP #i = 1 to 24.
>> COMPUTE syear)#i) = DATE.MDY(01,01,1988+#i).
>> end LOOP.
>> execute.
>>
>> The question is whether spss will do arithmetic on the 1988+#i. If it
>> won't, try this.
>>
>> Vector syear=s1988 to s2012.
>> LOOP #i = 1 to 24.
>> Compute #yr=1988+#i.
>> COMPUTE syear)#i) = DATE.MDY(01,01,#yr).
>> end LOOP.
>> execute.
>>
>> Gene Maguin
>>
>>
>> -----Original Message-----
>> From: SPSSX(r) Discussion [mailto:
>
>> SPSSX-L@.UGA
>
>> ] On Behalf Of Zana Dael
>> Sent: Friday, May 16, 2014 10:35 AM
>> To:
>
>> SPSSX-L@.UGA
>
>> Subject: looping with dates
>>
>> I am trying my hand at creating variables by looping, but I'm stuck.
>>
>> I want to create 24 date fields that will allow me to do calculations
>> by specific year. The 24 variables will have different dates but the
>> date will be the same for the individual variable. For example all
>> recrods for
>> s1988 will be the date 1/1/1989, and all records for s1989 will have
>> the date
>> 1/1/1990 and so on. I could have done this with 24 different compute
>> commands but I wanted to see if I can create looping syntax. And I
>> couldn't.
>>
>> Here is the syntax I created (which of course only gives me 1/1/1989
>> for everyone of the 24 variables).
>>
>>
>> LOOP #i = 1 to 24.
>> DO REPEAT syear = s1988 to s2012.
>> COMPUTE syear = DATE.MDY(01,01,1989).
>> end REPEAT.
>> end LOOP.
>> execute.
>>
>> But this gives me error (compute - the expression ends unexpectedly).
>>
>> LOOP #i = 1 to 24.
>> DO REPEAT syear = s1988 to s2011.
>> COMPUTE syear = DATE.MDY(01,01,1989)TO DATE.MDY(01,01,2012).
>> end REPEAT.
>> end LOOP.
>> execute.
>>
>> I would appreciate the help in fixing my syntax.
>>
>> Zana
>>
>> =====================
>> To manage your subscription to SPSSX-L, send a message to
>
>> LISTSERV@.UGA
>
>>  (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
>
>> LISTSERV@.UGA
>
>>  (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?"
> --
> View this message in context:
>
http://spssx-discussion.1045642.n5.nabble.com/looping-with-dates-tp5726106p5726110.html
> Sent from the SPSSX Discussion mailing list archive at Nabble.com.
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

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

> LISTSERV@.UGA

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

> LISTSERV@.UGA

>  (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?"
--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/looping-with-dates-tp5726106p5726114.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


Reply | Threaded
Open this post in threaded view
|

Re: looping with dates

Rick Oliver-3
In reply to this post by Jon K Peck
Unfortunately, some of this information did not make its way into the documentation of the more recent (and preferred) date functions.

Rick Oliver
Senior Information Developer
IBM Business Analytics (SPSS)
E-mail: [hidden email]




From:        Jon K Peck/Chicago/IBM@IBMUS
To:        [hidden email],
Date:        05/16/2014 02:26 PM
Subject:        Re: looping with dates
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




The date functions and formats all document the valid ranges.  month 13 is allowed and treated as wrapping.  Note also this usage:
yrmoda:

The month can range from 1 through 13. Month 13 with day 0 yields the last day of the year. For

example, YRMODA(1990,13,0) produces the day number for December 31, 1990. Month 13 with any

other day yields the day of the first month of the coming year--for example, YRMODA(1990,13,1)

produces the day number for January 1, 1991.

v The day can range from 0 through 31. Day 0 is the last day of the previous month regardless of

whether it is 28, 29, 30, or 31. For example, YRMODA(1990,3,0) yields 148791.00, the day number for

February 28, 1990.



Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
phone: 720-342-5621





From:        
David Marso <[hidden email]>
To:        
[hidden email],
Date:        
05/16/2014 12:57 PM
Subject:        
Re: [SPSSX-L] looping with dates
Sent by:        
"SPSSX(r) Discussion" <[hidden email]>




Problem is they don't really teach this stuff in school.
Not really much to VECTOR
VECTOR new(dim,format).
or
VECTOR old=oldvar01 TO oldvar99.
then loop through the beast.

Really hard even to glean it from intense RTFMing.
Who would figure month can be 13 and it will wrap to Jan?
while 14 gives a range error (why not let 14 -> Feb?).
One delightful thing about MATRIX is the really crazy stuff you can throw at
it.
It is also remarkably fast.
For example the following generates a 1000 x 3 matrix of uniform ,
multiplies it by 10 and truncates.
Then it takes the sum of squared pairwise differences of the rows and puts
them into a matrix Z and Z2 using 2 alternative methods.
MATRIX.
COMPUTE X=TRUNC(UNIFORM(1000,3)*10).
COMPUTE
Z={CSUM((X(:,1)-X(:,2))&**2),CSUM((X(:,1)-X(:,3))&**2),CSUM((X(:,2)-X(:,3))&**2)}.
COMPUTE Z2=T(DIAG(SSCP({X(:,1)-X(:,2),X(:,1)-X(:,3),X(:,2)-X(:,3)}))).
PRINT Z.
PRINT Z2.
END MATRIX.





bdates wrote
> Amen, Gene.  I'm constantly humbled. As much as I've used matrix, I'm
> woefully behind in the vector command with the standard database format.
> I'm going to school on all of this. Thanks.
>
> B
> ________________________________________
> From: SPSSX(r) Discussion [

> SPSSX-L@.UGA

> ] on behalf of Maguin, Eugene [

> emaguin@

> ]
> Sent: Friday, May 16, 2014 11:59 AM
> To:

> SPSSX-L@.UGA

> Subject: Re: looping with dates
>
> Yes, there is a typo. Thanks. No, I never would have guessed that those
> examples would work.
> The fun thing about this list is discovering how limited my
> conceptualization of the transformation commands actually is.
>
> Gene Maguin
>
>
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:

> SPSSX-L@.UGA

> ] On Behalf Of David Marso
> Sent: Friday, May 16, 2014 11:50 AM
> To:

> SPSSX-L@.UGA

> Subject: Re: looping with dates
>
> " I don't that spss will do arithmetic within that function."
>
> Sure it will.  The only restriction AFAIK is that the arguments in data
> aggregation functions evaluate to an INTEGER.
>
> For example COMPUTE booboo=DATE.MDY(1,1,1988.5).
> will politely inform you that:
>
>>One of the arguments to the DATE function is out of range or is not an
>>integer.  The result has been set to the system-missing value.
>
> Interesting.  Did you know that this is valid?
> NUMERIC booboo (ADATE).
> COMPUTE booboo=DATE.MDY(13,1,1988).
> EXECUTE.
> It will return 01/01/1989
>
> Interesting that
> COMPUTE booboo=DATE.MDY(2+1,1,1988) - 86400 .
> returns 02/29/1988 ie 1988 was a leap year.
> Neat trick for finding the last day of any particular month (subtract 1
> day from the first day of the following month)
>
> Your code assumes that s1988 TO s2012 already exist.
> Also a typo in syear)#).
> Note OP counted 24 variables but 1988-2012 add up to 25.
> See my post in this thread.
>
>
> Maguin, Eugene wrote
>> Try this. I'm not sure it will work because I don't that spss will do
>> arithmetic within that function.
>>
>> There's also a simpler way to do this. What you have is too complicated.
>>
>> Vector syear=s1988 to s2012.
>> LOOP #i = 1 to 24.
>> COMPUTE syear)#i) = DATE.MDY(01,01,1988+#i).
>> end LOOP.
>> execute.
>>
>> The question is whether spss will do arithmetic on the 1988+#i. If it
>> won't, try this.
>>
>> Vector syear=s1988 to s2012.
>> LOOP #i = 1 to 24.
>> Compute #yr=1988+#i.
>> COMPUTE syear)#i) = DATE.MDY(01,01,#yr).
>> end LOOP.
>> execute.
>>
>> Gene Maguin
>>
>>
>> -----Original Message-----
>> From: SPSSX(r) Discussion [mailto:
>
>> SPSSX-L@.UGA
>
>> ] On Behalf Of Zana Dael
>> Sent: Friday, May 16, 2014 10:35 AM
>> To:
>
>> SPSSX-L@.UGA
>
>> Subject: looping with dates
>>
>> I am trying my hand at creating variables by looping, but I'm stuck.
>>
>> I want to create 24 date fields that will allow me to do calculations
>> by specific year. The 24 variables will have different dates but the
>> date will be the same for the individual variable. For example all
>> recrods for
>> s1988 will be the date 1/1/1989, and all records for s1989 will have
>> the date
>> 1/1/1990 and so on. I could have done this with 24 different compute
>> commands but I wanted to see if I can create looping syntax. And I
>> couldn't.
>>
>> Here is the syntax I created (which of course only gives me 1/1/1989
>> for everyone of the 24 variables).
>>
>>
>> LOOP #i = 1 to 24.
>> DO REPEAT syear = s1988 to s2012.
>> COMPUTE syear = DATE.MDY(01,01,1989).
>> end REPEAT.
>> end LOOP.
>> execute.
>>
>> But this gives me error (compute - the expression ends unexpectedly).
>>
>> LOOP #i = 1 to 24.
>> DO REPEAT syear = s1988 to s2011.
>> COMPUTE syear = DATE.MDY(01,01,1989)TO DATE.MDY(01,01,2012).
>> end REPEAT.
>> end LOOP.
>> execute.
>>
>> I would appreciate the help in fixing my syntax.
>>
>> Zana
>>
>> =====================
>> To manage your subscription to SPSSX-L, send a message to
>
>> LISTSERV@.UGA
>
>>  (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
>
>> LISTSERV@.UGA
>
>>  (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?"
> --
> View this message in context:
>
http://spssx-discussion.1045642.n5.nabble.com/looping-with-dates-tp5726106p5726110.html
> Sent from the SPSSX Discussion mailing list archive at Nabble.com.
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

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

> LISTSERV@.UGA

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

> LISTSERV@.UGA

>  (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?"
--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/looping-with-dates-tp5726106p5726114.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


Reply | Threaded
Open this post in threaded view
|

Re: looping with dates

David Marso
Administrator
In reply to this post by Rick Oliver-3
The month 13 aspect is documented in the Universals section Data Aggregation functions DATE.MDY and the ilk and also YRMODA.
I just looked at the PDF file from version 11.5 and it is there.
The 0 to return the last day of previous month is interesting.  I didn't know that before.
I think I discovered the 13th month thing by accident one day about 20 years ago ;-)
Might have read it in the FM back then too, but some things gather cranium dust over time.

Rick Oliver wrote
Hmmm....I thought the documentation said something about 13 for month in
date functions being interpreted as January of the following year, but it
doesn't.

On a related noted, day values in date functions can be 0-31. If the month
has fewer than 31 days, then the date rolls over to the next month. That
is documented. If it's 0, it's interpreted as the last day of the previous
month. That was not previously documented but will be in the next release.



Rick Oliver
Senior Information Developer
IBM Business Analytics (SPSS)
E-mail: [hidden email]



From:   David Marso <[hidden email]>
To:     [hidden email],
Date:   05/16/2014 02:00 PM
Subject:        Re: looping with dates
Sent by:        "SPSSX(r) Discussion" <[hidden email]>



Problem is they don't really teach this stuff in school.
Not really much to VECTOR
VECTOR new(dim,format).
or
VECTOR old=oldvar01 TO oldvar99.
then loop through the beast.

Really hard even to glean it from intense RTFMing.
Who would figure month can be 13 and it will wrap to Jan?
while 14 gives a range error (why not let 14 -> Feb?).
One delightful thing about MATRIX is the really crazy stuff you can throw
at
it.
It is also remarkably fast.
For example the following generates a 1000 x 3 matrix of uniform ,
multiplies it by 10 and truncates.
Then it takes the sum of squared pairwise differences of the rows and puts
them into a matrix Z and Z2 using 2 alternative methods.
MATRIX.
COMPUTE X=TRUNC(UNIFORM(1000,3)*10).
COMPUTE
Z={CSUM((X(:,1)-X(:,2))&**2),CSUM((X(:,1)-X(:,3))&**2),CSUM((X(:,2)-X(:,3))&**2)}.
COMPUTE Z2=T(DIAG(SSCP({X(:,1)-X(:,2),X(:,1)-X(:,3),X(:,2)-X(:,3)}))).
PRINT Z.
PRINT Z2.
END MATRIX.





bdates wrote
> Amen, Gene.  I'm constantly humbled. As much as I've used matrix, I'm
> woefully behind in the vector command with the standard database format.
> I'm going to school on all of this. Thanks.
>
> B
> ________________________________________
> From: SPSSX(r) Discussion [

> SPSSX-L@.UGA

> ] on behalf of Maguin, Eugene [

> emaguin@

> ]
> Sent: Friday, May 16, 2014 11:59 AM
> To:

> SPSSX-L@.UGA

> Subject: Re: looping with dates
>
> Yes, there is a typo. Thanks. No, I never would have guessed that those
> examples would work.
> The fun thing about this list is discovering how limited my
> conceptualization of the transformation commands actually is.
>
> Gene Maguin
>
>
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:

> SPSSX-L@.UGA

> ] On Behalf Of David Marso
> Sent: Friday, May 16, 2014 11:50 AM
> To:

> SPSSX-L@.UGA

> Subject: Re: looping with dates
>
> " I don't that spss will do arithmetic within that function."
>
> Sure it will.  The only restriction AFAIK is that the arguments in data
> aggregation functions evaluate to an INTEGER.
>
> For example COMPUTE booboo=DATE.MDY(1,1,1988.5).
> will politely inform you that:
>
>>One of the arguments to the DATE function is out of range or is not an
>>integer.  The result has been set to the system-missing value.
>
> Interesting.  Did you know that this is valid?
> NUMERIC booboo (ADATE).
> COMPUTE booboo=DATE.MDY(13,1,1988).
> EXECUTE.
> It will return 01/01/1989
>
> Interesting that
> COMPUTE booboo=DATE.MDY(2+1,1,1988) - 86400 .
> returns 02/29/1988 ie 1988 was a leap year.
> Neat trick for finding the last day of any particular month (subtract 1
> day from the first day of the following month)
>
> Your code assumes that s1988 TO s2012 already exist.
> Also a typo in syear)#).
> Note OP counted 24 variables but 1988-2012 add up to 25.
> See my post in this thread.
>
>
> Maguin, Eugene wrote
>> Try this. I'm not sure it will work because I don't that spss will do
>> arithmetic within that function.
>>
>> There's also a simpler way to do this. What you have is too
complicated.
>>
>> Vector syear=s1988 to s2012.
>> LOOP #i = 1 to 24.
>> COMPUTE syear)#i) = DATE.MDY(01,01,1988+#i).
>> end LOOP.
>> execute.
>>
>> The question is whether spss will do arithmetic on the 1988+#i. If it
>> won't, try this.
>>
>> Vector syear=s1988 to s2012.
>> LOOP #i = 1 to 24.
>> Compute #yr=1988+#i.
>> COMPUTE syear)#i) = DATE.MDY(01,01,#yr).
>> end LOOP.
>> execute.
>>
>> Gene Maguin
>>
>>
>> -----Original Message-----
>> From: SPSSX(r) Discussion [mailto:
>
>> SPSSX-L@.UGA
>
>> ] On Behalf Of Zana Dael
>> Sent: Friday, May 16, 2014 10:35 AM
>> To:
>
>> SPSSX-L@.UGA
>
>> Subject: looping with dates
>>
>> I am trying my hand at creating variables by looping, but I'm stuck.
>>
>> I want to create 24 date fields that will allow me to do calculations
>> by specific year. The 24 variables will have different dates but the
>> date will be the same for the individual variable. For example all
>> recrods for
>> s1988 will be the date 1/1/1989, and all records for s1989 will have
>> the date
>> 1/1/1990 and so on. I could have done this with 24 different compute
>> commands but I wanted to see if I can create looping syntax. And I
>> couldn't.
>>
>> Here is the syntax I created (which of course only gives me 1/1/1989
>> for everyone of the 24 variables).
>>
>>
>> LOOP #i = 1 to 24.
>> DO REPEAT syear = s1988 to s2012.
>> COMPUTE syear = DATE.MDY(01,01,1989).
>> end REPEAT.
>> end LOOP.
>> execute.
>>
>> But this gives me error (compute - the expression ends unexpectedly).
>>
>> LOOP #i = 1 to 24.
>> DO REPEAT syear = s1988 to s2011.
>> COMPUTE syear = DATE.MDY(01,01,1989)TO DATE.MDY(01,01,2012).
>> end REPEAT.
>> end LOOP.
>> execute.
>>
>> I would appreciate the help in fixing my syntax.
>>
>> Zana
>>
>> =====================
>> To manage your subscription to SPSSX-L, send a message to
>
>> LISTSERV@.UGA
>
>>  (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
>
>> LISTSERV@.UGA
>
>>  (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?"
> --
> View this message in context:
>
http://spssx-discussion.1045642.n5.nabble.com/looping-with-dates-tp5726106p5726110.html

> Sent from the SPSSX Discussion mailing list archive at Nabble.com.
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

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

> LISTSERV@.UGA

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

> LISTSERV@.UGA

>  (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?"
--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/looping-with-dates-tp5726106p5726114.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
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?"