Reputation: 155
I am very new to SPSS and statistical programs in general. I've searched for the answer to this question but can't seem to find a straightforward answer.
I have one date variable (dateA) that I want to compare to multiple other date variables (date1, date2, date3...date1000+) with the datediff function, and create a separate datediff result variable for each computation.
I have tried doing this through the "compute variable" process on SPSS but it only allows me to choose a pair of dates at a time (i.e. adding the "TO" function for date1 TO dateX doesn't work). I would rather create an automated process to do this function for all of these other date variables automatically, and create datediff results for each (datediff1, datediff2, datediff3...).
e.g. dateA - date1 = datediff1; dateA - date2 = datediff2; dateA - date3 = datediff3...and so on (without having to compute each manually which would take forever).
The end goal is to find out how many of these many datediff results are <= 2 weeks.
Thanks for your help!
Upvotes: 2
Views: 283
Reputation: 11350
First use this to create some sample data:
DATA LIST FREE /dateA date1 date2 date3 (4ADATE10).
BEGIN DATA
1/1/2017 1/2/2017 1/7/2017 1/12/2017
1/2/2017 1/16/2017 1/10/2017 1/14/2017
1/3/2017 1/29/2017 2/1/2017 2/7/2017
END DATA.
Now to create a new set of variables containing the difference between the dates you can use do repeat
to loop through the dates and compare them:
do repeat DtList=date1 to date3/Diff=Diff1 to Diff3.
compute Diff=datediff(DtList, dateA, "weeks").
end repeat.
* now you can count the number of dates that have a two weeks difference or more.
COUNT Weeks2p=Diff1 Diff2 Diff3 (2 thru Hi).
But if all you need is to get the final count, you can do it without creating all the difference wariables, like this:
compute Weeks2p=0.
do repeat DtList=date1 to date3/Diff=Diff1 to Diff3.
compute Weeks2p=Weeks2p + (datediff(DtList, dateA, "weeks") ge 2).
end repeat.
Upvotes: 3