most recent date

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

most recent date

LaraVDB
Hi,

I have following dataset:

patient           visit1               visit2            visit3          
visit4          
Patient1        24/03/2017    25/03/2017   24/04/2017   11/09/2017
Patient2        28/07/2017                        05/09/2017
Patient3        17/07/2017    18/07/2017

I want to create another column that indicates which visit was the most
recent.
So Ideally for patient 1, the extra column will state 'visit4', for patient2
'visit3' and for patient 3 'visit2' (so not the actual dates).

Is this possible with spss?

Kind regards,
Lara



--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
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: most recent date

David Marso
Administrator
Presumably the data are entered in temporal order from left to right.
---
DATA LIST LIST
  /patient (A10) visit1  (EDATE) visit2  (EDATE) visit3  (EDATE) visit4
(EDATE) .
BEGIN DATA        
Patient1        24/03/2017    25/03/2017   24/04/2017   11/09/2017
Patient2        28/07/2017    .            05/09/2017
Patient3        17/07/2017    18/07/2017
END DATA.


STRING LastVisit (A8).
VECTOR v=visit1 TO visit4.
LOOP #=4 TO 1 BY -1.
DO IF NOT(MISSING(v(#))).
COMPUTE LastVisit=CONCAT("Visit",STRING(#,F1.0)).
BREAK.
END IF.
END LOOP.
LIST.
 
patient        visit1     visit2     visit3     visit4 LastVisit
 
Patient1   24.03.2017 25.03.2017 24.04.2017 11.09.2017 Visit4
Patient2   28.07.2017          . 05.09.2017          . Visit3
Patient3   17.07.2017 18.07.2017          .          . Visit2
 
 
Number of cases read:  3    Number of cases listed:  3



LaraVDB wrote

> Hi,
>
> I have following dataset:
>
> patient           visit1               visit2            visit3          
> visit4          
> Patient1        24/03/2017    25/03/2017   24/04/2017   11/09/2017
> Patient2        28/07/2017                        05/09/2017
> Patient3        17/07/2017    18/07/2017
>
> I want to create another column that indicates which visit was the most
> recent.
> So Ideally for patient 1, the extra column will state 'visit4', for
> patient2
> 'visit3' and for patient 3 'visit2' (so not the actual dates).
>
> Is this possible with spss?
>
> Kind regards,
> Lara
>
>
>
> --
> Sent from: http://spssx-discussion.1045642.n5.nabble.com/
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

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





-----
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
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
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: most recent date

Bruce Weaver
Administrator
Lara, just in case it is not clear, you only need the syntax starting at the
line:  STRING LastVisit(A8).  Everything before that is to help those of us
who do not have your data file generate a small file for demonstration
purposes.  

Also, to save a few keystrokes in the DATA LIST command, one could replace
this...

DATA LIST LIST
  /patient (A10) visit1  (EDATE) visit2  (EDATE) visit3  (EDATE) visit4
(EDATE) .

...with this:

DATA LIST LIST
  /patient (A10) visit1 to visit4 (4DATE) .


I first tried it with (4EDATE), but that generated both a warning and an
error message, as follows:

>Warning # 203 in column 36.  Text: 4E
>An 'E', beginning the exponent portion of a number, was not followed by any
digits.
>The symbol will be treated as an invalid special character.
 
>Error # 4160 in column 36.  Text: 4E
>The format contains an unrecognized symbol.
>Execution of this command stops.

Apparently SPSS is interpreting 4EDATE as an attempt to use scientific
notation.  



David Marso wrote

> Presumably the data are entered in temporal order from left to right.
> ---
> DATA LIST LIST
>   /patient (A10) visit1  (EDATE) visit2  (EDATE) visit3  (EDATE) visit4
> (EDATE) .
> BEGIN DATA        
> Patient1        24/03/2017    25/03/2017   24/04/2017   11/09/2017
> Patient2        28/07/2017    .            05/09/2017
> Patient3        17/07/2017    18/07/2017
> END DATA.
>
>
> STRING LastVisit (A8).
> VECTOR v=visit1 TO visit4.
> LOOP #=4 TO 1 BY -1.
> DO IF NOT(MISSING(v(#))).
> COMPUTE LastVisit=CONCAT("Visit",STRING(#,F1.0)).
> BREAK.
> END IF.
> END LOOP.
> LIST.
>  
> patient        visit1     visit2     visit3     visit4 LastVisit
>  
> Patient1   24.03.2017 25.03.2017 24.04.2017 11.09.2017 Visit4
> Patient2   28.07.2017          . 05.09.2017          . Visit3
> Patient3   17.07.2017 18.07.2017          .          . Visit2
>  
>  
> Number of cases read:  3    Number of cases listed:  3
>
>
>
> LaraVDB wrote
>> Hi,
>>
>> I have following dataset:
>>
>> patient           visit1               visit2            visit3          
>> visit4          
>> Patient1        24/03/2017    25/03/2017   24/04/2017   11/09/2017
>> Patient2        28/07/2017                        05/09/2017
>> Patient3        17/07/2017    18/07/2017
>>
>> I want to create another column that indicates which visit was the most
>> recent.
>> So Ideally for patient 1, the extra column will state 'visit4', for
>> patient2
>> 'visit3' and for patient 3 'visit2' (so not the actual dates).
>>
>> Is this possible with spss?
>>
>> Kind regards,
>> Lara
>>
>>
>>
>> --
>> Sent from: http://spssx-discussion.1045642.n5.nabble.com/
>>
>> =====================
>> To manage your subscription to SPSSX-L, send a message to
>
>> LISTSERV@.UGA
>
>>  (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
>
>
>
>
>
> -----
> Please reply to the list and not to my personal email.
> Those desiring my consulting or training services please feel free to
> email me.
> ---
> "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos
> ne forte conculcent eas pedibus suis."
> Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in
> abyssum?"
> --
> Sent from: http://spssx-discussion.1045642.n5.nabble.com/
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

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





-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
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
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: most recent date

David Marso
Administrator
Yeah, I got the same error but didn't remember whether (DATE) would resolve
correctly.


Bruce Weaver wrote

> Lara, just in case it is not clear, you only need the syntax starting at
> the
> line:  STRING LastVisit(A8).  Everything before that is to help those of
> us
> who do not have your data file generate a small file for demonstration
> purposes.  
>
> Also, to save a few keystrokes in the DATA LIST command, one could replace
> this...
>
> DATA LIST LIST
>   /patient (A10) visit1  (EDATE) visit2  (EDATE) visit3  (EDATE) visit4
> (EDATE) .
>
> ...with this:
>
> DATA LIST LIST
>   /patient (A10) visit1 to visit4 (4DATE) .
>
>
> I first tried it with (4EDATE), but that generated both a warning and an
> error message, as follows:
>
>>Warning # 203 in column 36.  Text: 4E
>>An 'E', beginning the exponent portion of a number, was not followed by
any

> digits.
>>The symbol will be treated as an invalid special character.
>  
>>Error # 4160 in column 36.  Text: 4E
>>The format contains an unrecognized symbol.
>>Execution of this command stops.
>
> Apparently SPSS is interpreting 4EDATE as an attempt to use scientific
> notation.  
>
>
>
> David Marso wrote
>> Presumably the data are entered in temporal order from left to right.
>> ---
>> DATA LIST LIST
>>   /patient (A10) visit1  (EDATE) visit2  (EDATE) visit3  (EDATE) visit4
>> (EDATE) .
>> BEGIN DATA        
>> Patient1        24/03/2017    25/03/2017   24/04/2017   11/09/2017
>> Patient2        28/07/2017    .            05/09/2017
>> Patient3        17/07/2017    18/07/2017
>> END DATA.
>>
>>
>> STRING LastVisit (A8).
>> VECTOR v=visit1 TO visit4.
>> LOOP #=4 TO 1 BY -1.
>> DO IF NOT(MISSING(v(#))).
>> COMPUTE LastVisit=CONCAT("Visit",STRING(#,F1.0)).
>> BREAK.
>> END IF.
>> END LOOP.
>> LIST.
>>  
>> patient        visit1     visit2     visit3     visit4 LastVisit
>>  
>> Patient1   24.03.2017 25.03.2017 24.04.2017 11.09.2017 Visit4
>> Patient2   28.07.2017          . 05.09.2017          . Visit3
>> Patient3   17.07.2017 18.07.2017          .          . Visit2
>>  
>>  
>> Number of cases read:  3    Number of cases listed:  3
>>
>>
>>
>> LaraVDB wrote
>>> Hi,
>>>
>>> I have following dataset:
>>>
>>> patient           visit1               visit2            visit3          
>>> visit4          
>>> Patient1        24/03/2017    25/03/2017   24/04/2017   11/09/2017
>>> Patient2        28/07/2017                        05/09/2017
>>> Patient3        17/07/2017    18/07/2017
>>>
>>> I want to create another column that indicates which visit was the most
>>> recent.
>>> So Ideally for patient 1, the extra column will state 'visit4', for
>>> patient2
>>> 'visit3' and for patient 3 'visit2' (so not the actual dates).
>>>
>>> Is this possible with spss?
>>>
>>> Kind regards,
>>> Lara
>>>
>>>
>>>
>>> --
>>> Sent from: http://spssx-discussion.1045642.n5.nabble.com/
>>>
>>> =====================
>>> To manage your subscription to SPSSX-L, send a message to
>>
>>> LISTSERV@.UGA
>>
>>>  (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
>>
>>
>>
>>
>>
>> -----
>> Please reply to the list and not to my personal email.
>> Those desiring my consulting or training services please feel free to
>> email me.
>> ---
>> "Nolite dare sanctum canibus neque mittatis margaritas vestras ante
>> porcos
>> ne forte conculcent eas pedibus suis."
>> Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff
>> in
>> abyssum?"
>> --
>> Sent from: http://spssx-discussion.1045642.n5.nabble.com/
>>
>> =====================
>> To manage your subscription to SPSSX-L, send a message to
>
>> LISTSERV@.UGA
>
>>  (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
>
>
>
>
>
> -----
> --
> Bruce Weaver

> bweaver@

> http://sites.google.com/a/lakeheadu.ca/bweaver/
>
> "When all else fails, RTFM."
>
> NOTE: My Hotmail account is not monitored regularly.
> To send me an e-mail, please use the address shown above.
>
> --
> Sent from: http://spssx-discussion.1045642.n5.nabble.com/
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

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





-----
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
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
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: most recent date

Jon Peck
In reply to this post by David Marso
Just for grins, here is a simple Python solution that does not assume anything about the order of the dates.

First, we define a Python function that evaluates a case.  It finds the maximum value of the variables, ignoring missings, and returns the index in the list (plus 1) prefixed by the string "visit".  It is assumed that there is always at least one nonmissing date.

begin program.
def f(*args):
    return "visit" + str(args.index(max(args)) + 1)
end program.

Then we use the spssinc trans extension command normally installed with Statistics to invoke the function on all cases and return the computed value.  type=6 sets the length of the string variable created.


spssinc trans result = lastvisit type=6
/formula="f(visit1, visit2, visit3, visit4)".



On Fri, Sep 15, 2017 at 8:59 AM, David Marso <[hidden email]> wrote:
Presumably the data are entered in temporal order from left to right.
---
DATA LIST LIST
  /patient (A10) visit1  (EDATE) visit2  (EDATE) visit3  (EDATE) visit4
(EDATE) .
BEGIN DATA
Patient1        24/03/2017    25/03/2017   24/04/2017   11/09/2017
Patient2        28/07/2017    .            05/09/2017
Patient3        17/07/2017    18/07/2017
END DATA.


STRING LastVisit (A8).
VECTOR v=visit1 TO visit4.
LOOP #=4 TO 1 BY -1.
DO IF NOT(MISSING(v(#))).
COMPUTE LastVisit=CONCAT("Visit",STRING(#,F1.0)).
BREAK.
END IF.
END LOOP.
LIST.

patient        visit1     visit2     visit3     visit4 LastVisit

Patient1   24.03.2017 25.03.2017 24.04.2017 11.09.2017 Visit4
Patient2   28.07.2017          . 05.09.2017          . Visit3
Patient3   17.07.2017 18.07.2017          .          . Visit2


Number of cases read:  3    Number of cases listed:  3



LaraVDB wrote
> Hi,
>
> I have following dataset:
>
> patient           visit1               visit2            visit3
> visit4
> Patient1        24/03/2017    25/03/2017   24/04/2017   11/09/2017
> Patient2        28/07/2017                        05/09/2017
> Patient3        17/07/2017    18/07/2017
>
> I want to create another column that indicates which visit was the most
> recent.
> So Ideally for patient 1, the extra column will state 'visit4', for
> patient2
> 'visit3' and for patient 3 'visit2' (so not the actual dates).
>
> Is this possible with spss?
>
> Kind regards,
> Lara
>
>
>
> --
> Sent from: http://spssx-discussion.1045642.n5.nabble.com/
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

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





-----
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

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



--
Jon K Peck
[hidden email]

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