Date Syntax Help Needed

Discussion in 'SPSS' started by Damir, Oct 18, 2011.

  1. Damir

    Damir Guest

    Hi All,

    I have three variables (DATE11) 18-OCT-2011

    startdate (date11) enddate (date11) arrestdate (date11)

    I would like to be able to create a var that indicates whether the
    arrest date occurred prior to start date, between start and end date,
    or after the end date.

    Any assistance would be greatly appreciated.

    Damir, Oct 18, 2011
    1. Advertisements

  2. Damir

    Bruce Weaver Guest

    Date variables are numeric. So just compare with the usual functions
    you would for numeric variables. E.g.,

    * Read in some sample data.
    data list list / startdate enddate arrestdate (3date11).
    begin data
    1-Jan-2010 31-Dec-2010 15-Jun-2009
    1-Jan-2010 31-Dec-2010 1-Jan-2010
    1-Jan-2010 31-Dec-2010 15-Jun-2010
    1-Jan-2010 31-Dec-2010 31-Dec-2010
    1-Jan-2010 31-Dec-2010 15-Jun-2011
    end data.

    compute #before = (arrestdate LT startdate).
    compute #between = range(arrestdate,startdate,enddate).
    compute #after = (arrestdate GT enddate).

    compute WhenArrested = #before + #between*2 + #after*3.
    formats WhenArrested (f1.0).

    value labels WhenArrested
    1 'Arrested before start date'
    2 'Arrested between start and end dates'
    3 'Arrested after end date'
    frequencies WhenArrested.
    Bruce Weaver, Oct 18, 2011
    1. Advertisements

  3. Damir

    Damir Guest

    Thank you Bruce... worked like a charm.

    Damir, Oct 18, 2011
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.