Incorporating Calculated Values Into Syntax

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

Incorporating Calculated Values Into Syntax

Krinsky, Alan-2
Incorporating Calculated Values Into Syntax

Is there a way to automate the counting of variables or cases to use in syntax?

For example, I need to figure out if a pharmacy prescription is close to the date of a particular office visit. Patients can have multiple visits and multiple prescriptions. For now, let's say each patient-office visit is its own case, but each patient has multiple prescriptions. I have one file of unique patient-office visit combinations. And, I have each unique patient-prescription date in a separate file; to find out how many prescriptions per patient, I can do cases to variables, which I will need to do anyway to match the two files (eventually it will be each case is unique patient-office visit followed by all of the patient's prescriptions). Or, I can run an AGGREGATE command and get a count that way, without restructuring.

My problem is that I then need to compare the office visit date with each prescription date. For example, in the past I have paused my program and done a visual/manual identification of the max prescriptions among all patients and then done this, with one line for each possible prescription date up to the max:


COMPUTE EventMatch = 0.
IF (prescriptiondate.1 >= OfficeVisitDate AND prescriptiondate.1 <= OfficeVisitDatePlus3Days) EventMatch = 1.
IF (prescriptiondate.2 >= OfficeVisitDate AND prescriptiondate.2 <= OfficeVisitDatePlus3Days) EventMatch = 1.
IF (prescriptiondate.3 >= OfficeVisitDate AND prescriptiondate.3 <= OfficeVisitDatePlus3Days) EventMatch = 1.
IF (prescriptiondate.4 >= OfficeVisitDate AND prescriptiondate.4 <= OfficeVisitDatePlus3Days) EventMatch = 1.
IF (prescriptiondate.5 >= OfficeVisitDate AND prescriptiondate.5 <= OfficeVisitDatePlus3Days) EventMatch = 1.
.
.
.
IF (prescriptiondate.31 >= OfficeVisitDate AND prescriptiondate.31 <= OfficeVisitDatePlus3Days) EventMatch = 1.


Obviously, this is bulky and also requires manual adjustment for each new group or time frame.

So, I have started to experiment with Vectors, DO REPEAT, and LOOP. For instance:


COMPUTE y = PrescriptionCount.
DO REPEAT pd = prescriptiondate.1 TO prescriptiondate.y .
IF (pd >= OfficeVisitDate AND pd <= OfficeVisitDatePlus3Days) EventMatch = 1.
END REPEAT.
EXECUTE.


This does not work, apparently for two reasons: one, the PrescriptionCount varies by patient; and two, DO REPEAT does not seem to be able to handle a variable like "y" for the max repeat.

It appears I can identify and insert manually the value of y, and this will save on the bulkiness above, but still not automate the process.

So, is there a way to identify what that max number is and use syntax to incorporate it into some sort of looping process to compare the dates? Manually, I can work with one group of patients at a time, but to insert all of this within Python, to run on multiple groups, I need to solve this automation problem.

Thank you for your help!

Alan


Alan D. Krinsky  PhD, MPH
Medical Management Interventions Manager
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: Incorporating Calculated Values Into Syntax

Richard Ristow
At 02:37 PM 5/5/2011, Krinsky, Alan wrote:

>Patients can have multiple visits and multiple prescriptions. For
>now, let's say each patient-office visit is its own case, but each
>patient has multiple prescriptions. I have one file of unique
>patient-office visit combinations. And, I have each unique
>patient-prescription date in a separate file

So: you have one file with one case per office visit, one file with
one record per prescription, yes?

>For example, I need to figure out if a pharmacy prescription is
>close to the date of a particular office visit.

It depends on what "close to" means. If you mean what prescriptions
are near the office visit BUT AFTER IT, and before any later office
visit -- that is, you're trying to find what office visit was the
stimulus for writing each prescription -- it can be done with an ADD
FILE in which visits and prescriptions are interleaved by patient and
date, and you use LAG to carry over to each prescription the date of
the last preceding office visit.

If, say, you want to find the closest office visit in either time
direction for every prescription, you have a true many-to-many merge.
That is now a solved problem (see "Many-to-many merge in SPSS", Thu,
26 Nov 2009); you can get a file of all pairs of office visits and
prescriptions, and select from those the cases where the prescription
is close to the date of the visit, by your criteria.

>To find out how many prescriptions per patient, I can do cases to
>variables, or run an AGGREGATE command and get a count that way,
>without restructuring.

Much the easier, I think.

>I then need to compare the office visit date with each prescription date.

Given that the solution you're describing is clumsy, and that there's
no clear simplification of the selection logic, I suggest the
many-to-many merge. That bypasses concern about maximum number of
prescriptions per patient, etc; and since there'll be only one office
visit and one prescription in each record, the selection logic is
much simplified.

Let us know how it works out; especially, if there are any questions
about the algorithm.

-Best wishes,
  Richard Ristow

=====================
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: Incorporating Calculated Values Into Syntax

Richard Ristow
In reply to this post by Krinsky, Alan-2
dPostscript:

At 02:37 PM 5/5/2011, Krinsky, Alan posted the code he's using now:

>I need to compare the office visit date with each prescription date.
>For example, in the past I have paused my program and done a
>visual/manual identification of the max prescriptions among all
>patients and then done this, with one line for each possible
>prescription date up to the max:
>
>COMPUTE EventMatch = 0.
>IF     (prescriptiondate.1 >= OfficeVisitDate
>     AND prescriptiondate.1 <= OfficeVisitDatePlus3Days)
>         EventMatch = 1.
(etc.)

I see, now, that you're only looking for prescription dates AFTER the
office visit date. That can be done by ADD FILES; you don't need the
many-to-many merge. Very roughly, like this, assuming both files are
sorted ascending by their dates; not tested.

GET FILE=Visits.
NUMERIC DATE (DATE11).
COMPUTE DATE = OfficeVisitDate.
DATASET NAME   PreppedVisits.

GET FILE=Scrips.
NUMERIC DATE (DATE11).
COMPUTE DATE = prescriptiondate.
DATASET NAME   PreppedScrips.

ADD FILES
   /FILE=PreppedVisits /* 'Visits' must be listed first */
   /FILE=PreppedScrips /IN=IsScrip
   /BY  PatientID DATE.

DO IF    IsScrip.
.  COMPUTE Physician       = LAG(Physician).
.  COMPUTE OfficeVisitDate = LAG(OfficeVisitDate).
.  COMPUTE #DaysDiff       = CTIME.DAYS(prescriptiondate
                                        -OfficeVisitDate).
>.  COMPUTE EventMatch     = RANGE(#DaysDiff,1,3).

=====================
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