Comparing Multiple Dates

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Comparing Multiple Dates

Krinsky, Alan-2
Comparing Multiple Dates

Does anyone know of a way to compare multiple dates (or other values) across variables?

What I have are three different date variables, and I want to identify (for each case) the most recent of the three dates. In addition, one or more of the values can be null for any particular case. I am told that in SAS it is possible in a single command to ask for the most recent value of multiple variables. But with SPSS, as far as I have been able to figure, I need to use the brute force method of writing dozens of lines of DO IF-ELSE IF code to encompass all possibilities of null and present values, plus running one-by-one comparisons (if Date1 > Date2 and Date1 > Date3, choose Date1, if Date1 > Date2 and Date3 > Date1, choose Date3, etc.).

I realize another way would be to run VARS to CASES and transform all three date variables into a single variable and then sort and select for most recent, but this strikes me as more cumbersome and prone to error than the brute force method.

I searched on the archive and in the manuals and on the web, but found no simpler approach. But I hope I am missing something.

Thank you, and be well!

Alan


Alan D. Krinsky  PhD, MPH
Senior Data Analyst
UMass Memorial Health Care
Hahnemann Campus
281 Lincoln St.
Room 212
Worcester, MA 01605
Phone: 508-334-5854
Fax: 508-793-6086
E-mail: [hidden email]

The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, transmission, re-transmission, dissemination or other use of, or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.
Reply | Threaded
Open this post in threaded view
|

Re: Comparing Multiple Dates

Jon K Peck
Why not just use max(date1, date2, date3)?

Jon Peck
Senior Software Engineer, IBM
[hidden email]
new phone: 720-342-5621




From:        "Krinsky, Alan" <[hidden email]>
To:        [hidden email]
Date:        08/09/2011 08:11 AM
Subject:        [SPSSX-L] Comparing Multiple Dates
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Does anyone know of a way to compare multiple dates (or other values) across variables?

What I have are three different date variables, and I want to identify (for each case) the most recent of the three dates. In addition, one or more of the values can be null for any particular case. I am told that in SAS it is possible in a single command to ask for the most recent value of multiple variables. But with SPSS, as far as I have been able to figure, I need to use the brute force method of writing dozens of lines of DO IF-ELSE IF code to encompass all possibilities of null and present values, plus running one-by-one comparisons (if Date1 > Date2 and Date1 > Date3, choose Date1, if Date1 > Date2 and Date3 > Date1, choose Date3, etc.).

I realize another way would be to run VARS to CASES and transform all three date variables into a single variable and then sort and select for most recent, but this strikes me as more cumbersome and prone to error than the brute force method.

I searched on the archive and in the manuals and on the web, but found no simpler approach. But I hope I am missing something.

Thank you, and be well!

Alan

Alan D. Krinsky  PhD, MPH
Senior Data Analyst

UMass Memorial Health Care

Hahnemann Campus

281 Lincoln St.

Room 212

Worcester, MA 01605

Phone: 508-334-5854

Fax: 508-793-6086

E-mail: [hidden email]

The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, transmission, re-transmission, dissemination or other use of, or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.

Reply | Threaded
Open this post in threaded view
|

Re: Comparing Multiple Dates

Maguin, Eugene
In reply to this post by Krinsky, Alan-2
Comparing Multiple Dates
Hi Alan,
 
I don't know what you mean by 'null' value. I'll assume you mean 'system missing' value.
 
If you just want to find the most recent, i.e., the largest, date stored in a given set of variables, i think the max function is what you need. However, if you also want to know which variable in the given set of variables contains the most recent value, something more complicated is required.
 
Gene Maguin


From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Krinsky, Alan
Sent: Tuesday, August 09, 2011 9:24 AM
To: [hidden email]
Subject: Comparing Multiple Dates

Does anyone know of a way to compare multiple dates (or other values) across variables?

What I have are three different date variables, and I want to identify (for each case) the most recent of the three dates. In addition, one or more of the values can be null for any particular case. I am told that in SAS it is possible in a single command to ask for the most recent value of multiple variables. But with SPSS, as far as I have been able to figure, I need to use the brute force method of writing dozens of lines of DO IF-ELSE IF code to encompass all possibilities of null and present values, plus running one-by-one comparisons (if Date1 > Date2 and Date1 > Date3, choose Date1, if Date1 > Date2 and Date3 > Date1, choose Date3, etc.).

I realize another way would be to run VARS to CASES and transform all three date variables into a single variable and then sort and select for most recent, but this strikes me as more cumbersome and prone to error than the brute force method.

I searched on the archive and in the manuals and on the web, but found no simpler approach. But I hope I am missing something.

Thank you, and be well!

Alan


Alan D. Krinsky  PhD, MPH
Senior Data Analyst
UMass Memorial Health Care
Hahnemann Campus
281 Lincoln St.
Room 212
Worcester, MA 01605
Phone: 508-334-5854
Fax: 508-793-6086
E-mail: [hidden email]

The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, transmission, re-transmission, dissemination or other use of, or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.