SPSS Statistics

SPSS Statistics

Your hub for statistical analysis, data management, and data documentation. Connect, learn, and share with your peers! 

 View Only
  • 1.  Use of DATEDIFF() for YEARS behaviour

    Posted Fri October 29, 2021 08:50 AM
    Hi, I am hoping someone may be able to confirm this across SPSS and versions.

    We have a data set of 10.5m records unique customers. We need to seperate them into the various age groups our marketing team need based on their age at a certain date. We have a report that comes out of SPSS for them.

    Historically this has been determined based on DATEDIFF(RENEWALDATE, BIRTHDATE, "years"). In looking at this function, it seems to truncate so everyone gets the same year, irrespective of birthdate i.e. Someone will get the same age being born on the 1st of Jan, as the person born on the 31st Dec.

    Thankfully this has meant that some customers get notified a few months earlier than would be usual through the year as they are allocated a higher age group than they should be in, but as we are going for a re-development I need to confirm that SPSS version of this functions behaviour and my assumptions about it are correct, that it only uses the YEAR part of the dates.

    I am secretly hoping that it returns the ACTUAL AGE of the customer.

    Cheers
    JB

    ------------------------------
    James Bollum Likely lad
    ------------------------------

    #SPSSStatistics


  • 2.  RE: Use of DATEDIFF() for YEARS behaviour

    Posted Fri October 29, 2021 09:13 AM
    Edited by System Admin Fri January 20, 2023 04:15 PM
    From the CSR...
    The DATEDIFF function calculates the difference between two date values and returns an integer (with any fraction component truncated) in the specified date/time units
    This mimics the calculation one would do in getting a driver's license or buying an alcoholic drink.
    The function uses the whole date, so someone born on, say June 1 would have the date tick over to another year at that date just as would happen in a bar.

    Here is an example
    COMPUTE ageAsOf10.29.21=datediff($time, bdate, "years").
    list variables bdate ageAsOf10.29.21.

    bdate          ageAsOf10.29.21

    01/01/2021 .  00
    01/01/2020  1.00
    10/28/2020  1.00
    10/31/2020  .00
    06/01/2021  .00
    --





  • 3.  RE: Use of DATEDIFF() for YEARS behaviour

    Posted Fri October 29, 2021 12:25 PM
    Edited by System Admin Fri January 20, 2023 04:36 PM
    Thanks for the reply Jon,  your example seems to be showing me what I actually want (hoped) to see, and all my assumptions about where the issue is happening is wrong.

    Users have reported the following results (not specifically fromt he function but from the process)

    bdate          ageAsOf10.29.21


    01/01/2020  1
    10/27/2020  1
    10/28/2020  1
    10/31/2020  1
    12/12/2020  1
    01/01/2021  0

    There must be something else going on in their process somewhere......

    ------------------------------
    James Bollum Likely lad
    ------------------------------