Transform Visit dates for each patients into visit days for each patients

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

Transform Visit dates for each patients into visit days for each patients

Hans-Christian Stahl-2
Dear SPSS List Members,

I have a dataset where the visit of a patient at an outdoor clinic is
the key of the dataset (VISID). Each visit case is characterized by an
patient id (PID) and a visit date (VIS_DATE). Therefore, each patient
id can appear more than one time.

Now I want to define a new variable: VIS_DAY.

I define the first visit of each patient by "day one". Problem: how do
I find the date of first visit for each patients and how do I write
this in SPSS syntax?

Then I want to define each visit of the respecitve patient by the
duration in days between the first visit and the respective date of
the visit.

Example:

VISID   PID             VIS_DATE                VIS_DAY
36              5               15 MAR 2010             1
58              5               16 MAR 2010             2
78              5               20 MAR 2010             6
3               6               16 MAR 2010             1
6               6               17 MAR 2010             2

Can someone helpt with the syntax for SPSS 18?

Thank you very much in advance!

Hans-Christian Stahl

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Transform Visit dates for each patients into visit days for each patients

Art Kendall
Copy and paste the syntax below into a new syntax window. Run it.
Verify whether it does what you want.



DATA LIST LIST /
   VISID(f3)   PID(f3)             VIS_DATE (date11)
wanted_VIS_DAY(f2).
BEGIN DATA
36              5               15-MAR-2010             1
58              5               16-MAR-2010             2
78              5               20-MAR-2010             6
3               6               16-MAR-2010             1
6               6               17-MAR-2010             2
103            6               16-MAR-2010             1
106            6               17-MAR-2010             2
end data.
numeric vis_day(f2) first_date (date11).
sort cases by pid vis_date.
compute vis_day =0.
do if $casenum eq 1 or pid ne lag(pid).
COMPUTE first_date = vis_date.
compute vis_day =1.
ELSE.
COMPUTE first_date =lag(first_date).
compute vis_day =DATEDIFF(vis_date,first_date,"DAYS") +1.
end if.
list.

Art Kendall
Social Research Consultants

On 2/15/2010 6:03 AM, Hans-Christian Stahl wrote:

> Dear SPSS List Members,
>
> I have a dataset where the visit of a patient at an outdoor clinic is
> the key of the dataset (VISID). Each visit case is characterized by an
> patient id (PID) and a visit date (VIS_DATE). Therefore, each patient
> id can appear more than one time.
>
> Now I want to define a new variable: VIS_DAY.
>
> I define the first visit of each patient by "day one". Problem: how do
> I find the date of first visit for each patients and how do I write
> this in SPSS syntax?
>
> Then I want to define each visit of the respecitve patient by the
> duration in days between the first visit and the respective date of
> the visit.
>
> Example:
>
> VISID   PID             VIS_DATE                VIS_DAY
> 36              5               15 MAR 2010             1
> 58              5               16 MAR 2010             2
> 78              5               20 MAR 2010             6
> 3               6               16 MAR 2010             1
> 6               6               17 MAR 2010             2
>
> Can someone helpt with the syntax for SPSS 18?
>
> Thank you very much in advance!
>
> Hans-Christian Stahl
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> [hidden email] (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the command
> INFO REFCARD
>

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: Transform Visit dates for each patients into visit days for each patients

Antoon Smulders
In reply to this post by Hans-Christian Stahl-2
Hi Hans-Christian,

If I understand you, you can use aggregate and datediff here.
Untested:
AGGREGATE OUTFILE * /BREAK PID
        /firstDate = MIN(VIS-DAT)
        /lastDate = MAX(VIS_DAT).
COMPUTE duration = DATEDIF(lastDate, firstDate).
EXECUTE /* not necessary */.

Antoon Smulders

-----Oorspronkelijk bericht-----
Van: SPSSX(r) Discussion [mailto:[hidden email]] Namens Hans-Christian Stahl
Verzonden: maandag 15 februari 2010 12:03
Aan: [hidden email]
Onderwerp: Transform Visit dates for each patients into visit days for each patients

Dear SPSS List Members,

I have a dataset where the visit of a patient at an outdoor clinic is
the key of the dataset (VISID). Each visit case is characterized by an
patient id (PID) and a visit date (VIS_DATE). Therefore, each patient
id can appear more than one time.

Now I want to define a new variable: VIS_DAY.

I define the first visit of each patient by "day one". Problem: how do
I find the date of first visit for each patients and how do I write
this in SPSS syntax?

Then I want to define each visit of the respecitve patient by the
duration in days between the first visit and the respective date of
the visit.

Example:

VISID   PID             VIS_DATE                VIS_DAY
36              5               15 MAR 2010             1
58              5               16 MAR 2010             2
78              5               20 MAR 2010             6
3               6               16 MAR 2010             1
6               6               17 MAR 2010             2

Can someone helpt with the syntax for SPSS 18?

Thank you very much in advance!

Hans-Christian Stahl

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD