Search code examples
datespss

Using SELECT IF to recode one date from four variables in SPSS


Self-taught at SPSS here. Need to know the appropriate syntax to recode four DATE variables into one, based on which would be the latest date. I have four DATE variables in a dataset with 165 cases:

wnd_heal_date
wnd_heal_d14_date
wnd_heal_d30_date
wnd_heal_3m_date

And each variable may or may not contain a value for each case. I want to recode a new variable which scans the dates from all four and only selects the one that is the latest and puts it into a new variable (x_final_wound_heal_date).

How to use the SELECT IF function for this purpose?


Solution

  • select if function selects rows in the data, and so is not appropriate for this case. What you can do is this instead:

    compute x_final_wound_heal_date = 
        max(wnd_heal_date, wnd_heal_d14_date, wnd_heal_d30_date, wnd_heal_3m_date).
    VARIABLE LABELS   x_final_wnd_heal_date 'Time to definitive wound healing (days)'. 
    VARIABLE LEVEL   x_final_wnd_heal_date(SCALE). 
    ALTER TYPE x_final_wnd_heal_date(DATE11).
    

    This will put the latest of available date values in the new variable.