creating a value for vectors

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

creating a value for vectors

rich reeves
Hi I have gotten stuck and am hoping someone can help.

I have a bunch of different files that I want to run the same analysis on
and would like to the code to change based on the attributes of the file.

Specifically, I have a file where a unique individual has multiple records
based on the number of times they used a service.  I need to determine those
who used the service in a given period of time, for those who didn't did
they use a difference serivice for the same period, for those not in either
of the first two conditions where they cured prior to the time period of
interest.

I have written a command sequence that works using a CASESTOVARS command and
vectors in loops to find values in relevant fields.

Can anyone tell me if there is a way to grab the maximum value from the
CASESTOVARS procedure and use it in the vector and loop commands?  I can
create a new variable from the CASESTOVARS command and get the max value
from it but don't know how to get that into the code dynamically.

or...if there is an easier way to do this let me know.
Reply | Threaded
Open this post in threaded view
|

Re:creating a value for vectors

Jerabek Jindrich
Hi Rich,

You can use the number dynamicaly doing this:
- compute the value
- Write an outfile which defines macro, the macro conains your value
WRITE OUTFILE='c:\temp\define n.sps' /'DEFINE !n()'n'!ENDDEFINE.'.
-INCLUDE the file
-use the macro !n where you want to use your value

see this site for an example:
http://www.spsstools.net/Syntax/SelfAdjustingSyntax/AutomatedDataTransformFromTallToWide.txt

HTH
Jindra

> ------------ Původní zpráva ------------
> Od: rich reeves <[hidden email]>
> Předmět: creating a value for vectors
> Datum: 07.5.2007 18:15:43
> ----------------------------------------
> Hi I have gotten stuck and am hoping someone can help.
>
> I have a bunch of different files that I want to run the same analysis on
> and would like to the code to change based on the attributes of the file.
>
> Specifically, I have a file where a unique individual has multiple records
> based on the number of times they used a service.  I need to determine those
> who used the service in a given period of time, for those who didn't did
> they use a difference serivice for the same period, for those not in either
> of the first two conditions where they cured prior to the time period of
> interest.
>
> I have written a command sequence that works using a CASESTOVARS command and
> vectors in loops to find values in relevant fields.
>
> Can anyone tell me if there is a way to grab the maximum value from the
> CASESTOVARS procedure and use it in the vector and loop commands?  I can
> create a new variable from the CASESTOVARS command and get the max value
> from it but don't know how to get that into the code dynamically.
>
> or...if there is an easier way to do this let me know.
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: creating a value for vectors

Richard Ristow
In reply to this post by rich reeves
At 12:01 PM 5/7/2007, rich reeves wrote:

>Specifically, I have a file where a unique individual has multiple
>records based on the number of times they used a service.  I need to
>determine those who used the service in a given period of time, for
>those who didn't did they use a difference serivice for the same
>period, for those not in either of the first two conditions where they
>cured prior to the time period of interest.
>
>I have written a command sequence that works using a CASESTOVARS
>command and vectors in loops to find values in relevant fields. Can
>anyone tell me if there is a way to grab the maximum value from the
>CASESTOVARS procedure and use it in the vector and loop commands?

There are two ways to create code dynamically, based on data(*). One is
to write a file with syntax based on the data and then INCLUDE it, as
Jerabek Jindrich suggested. The other is to read the data values and
generate the code with Python, if you have SPSS 14 or 15. However -

>if there is an easier way to do this let me know.

Most problems like this can be solved pretty easily with the data still
in 'long' form, multiple records per patient, not needing CASESTOVARS
at all. (In fact, it's easy enough that it's often worth going the
other way: if you start with one record per patient, use VARSTOCASES or
XSAVE to 'unroll' to a separate record per event, and work from there.)

In your case, suppose your data includes
PatientID  Unique identifier for patient
EventDT    Date of event recorded in this record
Service    Service used
Cured      Cured, at this point?

Now, suppose also that the beginning and ending dates of your period
are fixed: Month1/Day1/Year1 to Month2/Day2/Year2. (If the dates vary
from run to run, you read them from a file and merge with your data,
probably using MATCH FILES, and proceed.) DON'T just copy this code; I
don't have your data, and it probably has some significant differences
from this. And I've copied the logic you seemed to ask for, but it may
not be precisely what you want. And I haven't tested, so there may be
bugs. But this is the idea.

NUMERIC
    Used1   /* Use of service 1 in the time period
    Used2   /* Use of service 2 in the time period
    CureBfr /* Cure, before the beginning of the period
    (F2).

IF      EventDt LT DATE.MDY(Month1,Day1,Year1)
     AND Cured   EQ 1
         CureBfr  = 1.

DO IF   EventDt GE DATE.MDY(Month1,Day1,Year1)
     AND EventDt LE DATE.MDY(Month2,Day2,Year2).
.  IF Service EQ 1
         Used1  = 1.
.  IF Service EQ 2
         Used2  = 1.
END IF.
RECODE  Used1 Used2 CureBfr (MISSING=0).

AGGREGATE  OUTFILE=*
    /BREAK=PatientID
    /Used1   'Used service 1 in relevant period' =MAX(Used1)
    /Used2   'Used service 2 in relevant period' =MAX(Used2)
    /CureBfr 'Cured before the relevant period'  =MAX(CureBfr).

NUMERIC   USAGE (F2).
VAR LABEL USAGE 'Service used in relevant period'.
VAL LABEL USAGE
   0 'None'
   1 'Service 1'
   2 'Svc 2, not 1'
   3 'Nthr, but cured'
   9 'LOGIC ERROR'.

COMPUTE    USAGE = 9 /* Precaution; DO IF is tricky */ .
DO IF   Used1   EQ 1.
.  COMPUTE USAGE = 1.
ELSE IF Used2   EQ 1.
.  COMPUTE USAGE = 2.
ELSE IF CureBfr EQ 1.
.  COMPUTE USAGE = 3.
ELSE.
.  COMPUTE USAGE = 0.
END IF.

..........................................
(*) It's never wise to say "there are two" and be smug you know them
all. However, these are the only two I know of, from experience or
mention on this list, and it's a rare technique that isn't mentioned
here, sooner or later.