|
Hi All,
I'm trying to create/calculate a slew of variables that contain the number of days between consecutive dates.
So, basically create DateDiff_1... which equals the number of days between CONTACT_DATE_1 and CONTACT_DATE_2...
...create DateDiff_2... which equals the number of days between CONTACT_DATE_2 and CONTACT_DATE_3...
...then repeat this over and over until reaching DateDiff_1827.
I put this together....
DO REPEAT
x = CONTACT_DATE_1 to CONTACT_DATE_1827 /y = DateDiff_1 to DateDiff_1827. COMPUTE y = DATEDIF(x, x+1, "days"). END REPEAT. EXECUTE. ...but it always cranks out a 0 into the cells.
Anybody have any thoughts where I went wrong... I'm just not seeing it!
The only thing I can think of is that in the COMPUTE y = DATEDIF(x, x+1, "days") that it is subtracting the x date from itself instead of subtracting the next date (x+1) from x, but not sure how to correct if this is the problem.
Any help is greatly appreciated!
Cheers
Derek
-- Dr. Derek J. Quinlan Research Project Coordinator Psychology Lecturer University of Western Ontario London, Ontario Mailing Address: Dr. Derek J. Quinlan The University of Western Ontario Westminster Hall, Suite 326E London, ON N6A 3K7 |
|
I think what your code is doing is adding one second to the value of date x and then calculating the date difference between x and x + one second, which in days is 0 days. You need three variable lists.
Hi All, I'm trying to create/calculate a slew of variables that contain the number of days between consecutive dates. So, basically create DateDiff_1... which equals the number of days between CONTACT_DATE_1 and CONTACT_DATE_2... ...create DateDiff_2... which equals the number of days between CONTACT_DATE_2 and CONTACT_DATE_3... ...then repeat this over and over until reaching DateDiff_1827. I put this together.... DO REPEAT x = CONTACT_DATE_1 to CONTACT_DATE_1827 /y = DateDiff_1 to DateDiff_1827. COMPUTE y = DATEDIF(x, x+1, "days"). END REPEAT. EXECUTE. ...but it always cranks out a 0 into the cells. Anybody have any thoughts where I went wrong... I'm just not seeing it! The only thing I can think of is that in the COMPUTE y = DATEDIF(x, x+1, "days") that it is subtracting the x date from itself instead of subtracting the next date (x+1) from x, but not sure how to correct if this is the problem. Any help is greatly appreciated! Cheers Derek -- Dr. Derek J. Quinlan Research Project Coordinator Psychology Lecturer University of Western Ontario London, Ontario Mailing Address: Dr. Derek J. Quinlan The University of Western Ontario Westminster Hall, Suite 326E London, ON N6A 3K7 |
|
In reply to this post by Derek Quinlan
Derek,
Rick is right. If you want to use a do repeat you need three variable lists. Like this. By the way, you can have only 1826 differences. DO REPEAT x=CONTACT_DATE_1 to CONTACT_DATE_1826/y=CONTACT_DATE_2 to CONTACT_DATE_1827/ z=DateDiff_1 to DateDiff_1826. COMPUTE z=DATEDIF(x,y,"days"). END REPEAT. EXECUTE. Another way is to use a vector and a loop structure. Vector x=CONTACT_DATE_1 to CONTACT_DATE_1827/DateDiff(1826). Loop #i=1 to 1826. COMPUTE datediff(#i)=DATEDIF(x(#i),x(#i+1),"days"). End loop. Execute. Gene Maguin ===================== 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 |
| Free forum by Nabble | Edit this page |
