Nearest Date

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Nearest Date

DKUKEC
Dear Listers,

I have included below my example dataset that contains arrest records for persons enrolled in programming - each row represents charges (sorted by most serious offenses) associated with an unqiue arrest.  I have drafted syntax that identifies an arrest "nearest" to the "prior to program start date."  What I was wondering is whether there is a better way to do this, since my syntax is rather lengthy and inefficient.  

Regards,
Damir

** EXAMPLE DATA *********************************** .
DATA LIST FREE / RPUID (F4) CASE_ID (A17) STARTDATE (DATE11) ENDDATE (DATE11) ARRESTDATE (DATE11) MSO (F1).
BEGIN DATA.
6294 2005MMXXXX0 18-Apr-2005 18-MAY-2005 01-APR-1999 2
6294 2005MMXXXX0 18-Apr-2005 18-MAY-2005 01-APR-1999 1
6294 2005MMXXXX1 18-Apr-2005 18-MAY-2005 01-APR-2005 2
6294 2005MMXXXX1 18-Apr-2005 18-MAY-2005 01-APR-2005 1
6294 2005MMXXXX2 18-Apr-2005 18-MAY-2005 01-JAN-2007 2
6294 2005MMXXXX2 18-Apr-2005 18-MAY-2005 01-JAN-2007 1
6294 2005MMXXXX2 18-Apr-2005 18-MAY-2005 01-JAN-2007 3
6294 2005MMXXXX2 18-Apr-2005 18-MAY-2005 01-JAN-2007 9999
6294 2005MMXXXX5 18-Apr-2005 18-MAY-2005 01-JAN-2008 1
6294 2005MMXXXX5 18-Apr-2005 18-MAY-2005 01-JAN-2008 3
6294 2005MMXXXX5 18-Apr-2005 18-MAY-2005 01-JAN-2008 9999
1234 2005MMXXXX2 27-May-2005 27-SEP-2005 20-MAY-2005 3
1234 2005MMXXXX2 27-May-2005 27-SEP-2005 20-MAY-2005 1
1234 2005MMXXXX2 27-May-2005 27-SEP-2005 20-MAY-2005 2
1234 2005MMXXXX2 27-May-2005 27-SEP-2005 20-MAY-2005 9999
4321 2010MMXXXX1 23-JAN-2010 23-JAN-2010 23-JAN-2010 3
6294 2005MMXXXX4 18-Apr-2005 18-MAY-2005 01-MAY-2005 1
6294 2005MMXXXX4 18-Apr-2005 18-MAY-2005 01-MAY-2005 3
END DATA.
DATASET NAME EXAMPLE.

********************************

SORT CASES BY RPUID (A) CASE_ID (A) ARRESTDATE (A) STARTDATE (A) MSO (A).
* DATE and TIME Wizard: DAYS.
COMPUTE  BEFOREDAYS=DATEDIF(ARRESTDATE, STARTDATE, "days").
VARIABLE LABELS  BEFOREDAYS "Days Between Arrest Date and StartDate".
VARIABLE LEVEL  BEFOREDAYS (SCALE).
FORMATS  BEFOREDAYS (F5.0).
VARIABLE WIDTH BEFOREDAYS (5).
EXECUTE.
************************ .

NUMERIC TEMP (F4.2).
DO IF BEFOREDAYS <0.
COMPUTE TEMP = BEFOREDAYS * -1.
END IF.
IF MISSING (TEMP) TEMP = LAG (TEMP) +1.
SORT CASES BY RPUID TEMP (A) MSO (A).
EXECUTE.

SORT CASES BY RPUID TEMP (A).
MATCH FILES FILE = * / BY RPUID / FIRST = INSTANT_MSO .
MATCH FILES FILE = * / BY RPUID / FIRST = INSTANT_CASE .
SORT CASES BY RPUID (D) INSTANT_CASE (D).
IF CASE_ID EQ LAG (CASE_ID) INSTANT_CASE=LAG (INSTANT_CASE).
VARIABLE LABELS INSTANT_MSO "Instant Arrest Charge by MSO - Prior to Program Start" .
VARIABLE LABELS INSTANT_CASE "Intstant Arrest Case (ALL CHARGES IN CASE) - Prior to Prorgam Start - Study Period (SPSS)".
EXECUTE.

SORT CASES BY RPUID (A) CASE_ID (A) ARRESTDATE (A) STARTDATE (A) MSO (A).
EXECUTE.

MATCH FILES FILE=* /DROP=TEMP .
EXECUTE.