IF calculation with dates

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

IF calculation with dates

mdspss
Hi, I am trying to figure out the following syntax:

IF (dateA<dateB-2days) C=1. i.e. i want to subtract two days from date B and check if date A preceded that. How can I do code that?

Secondly, how can i repeat this for a number of different non-consecutive date columns, e.g also for date pair D&E, F&G etc.

Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: IF calculation with dates

David Marso
Administrator
DATA LIST LIST / Date_A Date_B Date_C (3ADATE).
BEGIN DATA
10/02/2014 10/03/2014 10/08/2014
11/14/2014 11/17/2014 11/18/2014
END DATA.

DO REPEAT D1=Date_A Date_B / D2=Date_B Date_C /Flag=Flag_AB Flag_BC .
COMPUTE Flag=DATEDIFF(D2,D1,"Days") LT 2.
END REPEAT.
LIST.

    Date_A     Date_B     Date_C       Flag_AB      Flag_BC

10/02/2014 10/03/2014 10/08/2014       1.00        .00
11/14/2014 11/17/2014 11/18/2014         .00      1.00


Number of cases read:  2    Number of cases listed:  2

<quote author="mdspss">
Hi, I am trying to figure out the following syntax:

IF (dateA<dateB-2days) C=1. i.e. i want to subtract two days from date B and check if date A preceded that. How can I do code that?

Secondly, how can i repeat this for a number of different non-consecutive date columns, e.g also for date pair D&E, F&G etc.

Thanks.
</quote>
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: IF calculation with dates

Maguin, Eugene
In reply to this post by mdspss
One way is using the datediff function; the other is to use ordinary substraction of 2 days expressed as seconds. Then embed that piece in a do repeat.

IF (datediff(dateB,dateA,"days") gt 2) C=1.

IF (dateA < (dateB-2*24*3600)) C=1.

Gene Maguin

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of mdspss
Sent: Tuesday, December 02, 2014 8:18 PM
To: [hidden email]
Subject: IF calculation with dates

Hi, I am trying to figure out the following syntax:

IF (dateA<dateB-2days) C=1. i.e. i want to subtract two days from date B and check if date A preceded that. How can I do code that?

Secondly, how can i repeat this for a number of different non-consecutive date columns, e.g also for date pair D&E, F&G etc.

Thanks.




--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/IF-calculation-with-dates-tp5728093.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: IF calculation with dates

David Marso
Administrator
For sake of completeness there is also the CTIME.DAYS function ;-)
--
Maguin, Eugene wrote
One way is using the datediff function; the other is to use ordinary substraction of 2 days expressed as seconds. Then embed that piece in a do repeat.

IF (datediff(dateB,dateA,"days") gt 2) C=1.

IF (dateA < (dateB-2*24*3600)) C=1.

Gene Maguin

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of mdspss
Sent: Tuesday, December 02, 2014 8:18 PM
To: [hidden email]
Subject: IF calculation with dates

Hi, I am trying to figure out the following syntax:

IF (dateA<dateB-2days) C=1. i.e. i want to subtract two days from date B and check if date A preceded that. How can I do code that?

Secondly, how can i repeat this for a number of different non-consecutive date columns, e.g also for date pair D&E, F&G etc.

Thanks.




--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/IF-calculation-with-dates-tp5728093.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to <email>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
[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?"